tags:

views:

631

answers:

3

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

+3  A: 

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();
Darin Dimitrov
Thanks :) I saw that option, unfortunately that code is in the library assembly. It doesn't know about other assemblies or mappings in them.Can you add them after your session is built/opened?
Jay
+1  A: 

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).

Rashack
Thanks, that helps by confirming what I thought :)
Jay
A: 

I changed the underlying library to allow adding assemblies at initialization. That seems to work just great.

Jay