Background:
I'm getting a mapping failure when trying to use nHibernate. The application consists of several assemblies. One of the assemblies is a library of useful routines and the other is application code that uses the library. The library assembly adds itself to the nHibernate configuration but since it doesn't know about other assemblies it doesn't add them. My xml mapping file is located in the application assembly. I think it's not finding it because it's not looking in the application assembly.
Question: Can you map to a class in an arbitrary assembly without adding it to the configuration?
If not, can you add a mapping at run time?
Thanks
p.s. I did make sure the mapping file was marked as an embedded resource
Update - Apr 3 '09
I changed the underlying library to allow adding assemblies at initialization. That seems to work just great.
You can add mappings at runtime at the moment your session factory is being constructed:
ISessionFactory sf = new Configuration()
.AddFile("Item.hbm.xml")
.AddFile("Bid.hbm.xml")
.BuildSessionFactory();
or with assemblies:
ISessionFactory sf = new Configuration()
.AddAssembly("NHibernate.Auction")
.BuildSessionFactory();
Re your comment - no you cannot add mappings once you constructed your session factory. You can however re-create the session factory. Keep in mind though that it can be expensive operation (a second or so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With