It is possible to mix and match; that is use your current projects xml files and start to use the mapping by code. So if you find yourself in this position:-
I am ready to start using NHibernate 3.2 in an old project and utilise all the goodness that the mapping by code syntax gives me, but I am not quite ready to move over all my xml files yet.I realise that one could argue about testing, that is if all my tests cover mappings then the conversion should not cause friction. However some of us are left with named queries right?
The solution is quite simple, first you need to define your web.config (or external hibernate config file) as:-
<configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="dialect"> NHibernate.Dialect.MySQL5Dialect </property> <mapping assembly="Domain.Model" /> </session-factory> </hibernate-configuration>Then in your start up code:-
var mapper = new ModelMapper(); mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes()); //Notice the .Configure, this is the magic that allows you to // use the mixed mappings var configure = new Configuration().Configure(); configure.DataBaseIntegration(x => { x.Dialect<MySQL5Dialect>(); x.ConnectionStringName = "db"; }).CurrentSessionContext<WebSessionContext>(); configure.AddDeserializedMapping(mapping, "Domain"); SessionFactory = configure.BuildSessionFactory();If you notice we are making a call to .Configure. Because of this call then NHibernate always needs a hibernate-configuration section inside your web.config. We are therefore instructing NHibernate to configure the mappings as usual in web.config and then configure using the new mapping by code syntax (which is based on loquacious).
After you have converted your XML you can remove all references in web.config and change:-
var configure = new Configuration().Configure();to just:-
var configure = new Configuration();
I personally have used this technique as I still have a few named queries left over in my XML files and have not yet moved them out, therefore this mixed mapping has really helped me out.
You got to love the simplicity of being able to mix old and new, well done to the NHibernate team for taking away some pain points.
This comment has been removed by a blog administrator.
ReplyDeleteThanks !
ReplyDeleteIt was really a nice post and Thanks for the info
ReplyDelete.Net Online Training Hyderabad
izmir
ReplyDeleteErzurum
Diyarbakır
Tekirdağ
Ankara
JMFFSV
Konya
ReplyDeleteKayseri
Malatya
Elazığ
Tokat
0BYOU7
İstanbul Lojistik
ReplyDeleteZonguldak Lojistik
Konya Lojistik
Ağrı Lojistik
Ordu Lojistik
KHQ4G
48A26
ReplyDeleteParibu Güvenilir mi
Ankara Asansör Tamiri
Batman Evden Eve Nakliyat
Yozgat Evden Eve Nakliyat
Sivas Evden Eve Nakliyat
4DE5D
ReplyDeleteTrabzon Şehir İçi Nakliyat
Artvin Şehir İçi Nakliyat
Bitmex Güvenilir mi
Balıkesir Lojistik
Sinop Evden Eve Nakliyat
Karabük Lojistik
Uşak Lojistik
Azero Coin Hangi Borsada
Düzce Parça Eşya Taşıma
4D569
ReplyDeletekırşehir mobil sesli sohbet
görüntülü sohbet yabancı
bitlis telefonda görüntülü sohbet
bolu canlı sohbet odası
rastgele sohbet odaları
konya sesli mobil sohbet
amasya rastgele görüntülü sohbet uygulamaları
kilis mobil sohbet
hakkari sesli sohbet odası
70AF2
ReplyDeleteyabancı görüntülü sohbet
Adana Parasız Görüntülü Sohbet
aydın canlı sohbet odaları
gümüşhane telefonda rastgele sohbet
Kilis Rastgele Sohbet Uygulaması
canlı sohbet odaları
kırşehir canli goruntulu sohbet siteleri
istanbul yabancı görüntülü sohbet siteleri
adana görüntülü sohbet yabancı
71F0F
ReplyDeletebursa mobil sohbet siteleri
nevşehir rastgele görüntülü sohbet uygulamaları
ağrı en iyi ücretsiz sohbet uygulamaları
telefonda görüntülü sohbet
Konya Telefonda Kızlarla Sohbet
bingöl canlı sohbet siteleri
burdur en iyi sesli sohbet uygulamaları
eskişehir sesli sohbet sesli chat
tokat kızlarla canlı sohbet
8E9B1
ReplyDeleteKripto Para Kazma Siteleri
Kripto Para Madenciliği Nedir
Facebook Beğeni Satın Al
Threads Beğeni Satın Al
Periscope Beğeni Hilesi
Expanse Coin Hangi Borsada
Bee Coin Hangi Borsada
Likee App Beğeni Hilesi
Binance Yaş Sınırı
CA4B3
ReplyDeleteSoundcloud Takipçi Satın Al
Yeni Çıkan Coin Nasıl Alınır
Keep Coin Hangi Borsada
Referans Kimliği Nedir
Kripto Para Nasıl Üretilir
Pitbull Coin Hangi Borsada
Bitcoin Kazanma
Bitcoin Kazanma
Coin Para Kazanma
96DE2
ReplyDeletedebank
zkswap
uniswap
defillama
quickswap
spookyswap
poocoin
satoshivm
bscpad
RYTHRTYJYU
ReplyDeleteشركة مكافحة حشرات