I have an nHibernate Base class and have the function to return the session like this:
private static ISession OpenMySession()
{
var configuration = new Configuration();
return Fluently.Configure(configuration)
.Mappings(cfg => {
cfg.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly());
}).BuildConfiguration().BuildSessionFactory().OpenSession();
}
I have domain classes in another project. After opening the session when I try to get the data it is returning null values each time when I called from external application:
public static IList<T> GetOjectList<T>() where T : class
{
IList<T> list;
try {
ICriteria criteria = session.CreateCriteria<T>();
list = criteria.List<T>();
}
catch (Exception ex) {
throw;
}
return list;
}
If I run standard SQL statement using CreateSQLQuery function of session, I’m getting the result set.
I have defined a domain class and mapping in the same assembly and I’m getting the object data using the above function.
I’m assuming that Fluent is unable to resolve the namespace when I call this function from outside this assembly. Please help me to resolve this problem.
i think you should use Assembly.GetEntryAssembly() if you want to load mappings from startup project instead of Assembly.GetExecutingAssembly() . GetExecutingAssembly() “Gets the assembly that contains the code that is currently executing” so it will be always assembly in which base class is placed.