I have my nHibernate setup and working correctly with QueryOver for most queries, however, whenever I try to do a HQL CreateQuery I get the exception that the entity isn't mapped. I can confirm that the same entity works fine using QueryOver.
Note: I am using fluent nHibernate
Any ideas what would cause this?
If you have disabled auto-import in your mappings (<hibernate-mapping auto-import="false">
), then you will have to use fully-qualified class names everywhere in your queries, unqualified class names won't work.
Otherwise, enable auto-import.
Conventions.Setup(x =>
{
x.Add(FluentNHibernate.Conventions.Helpers.AutoImport.Always()); // AutoImport.Never
}); // End FluentMappings.Conventions.Setup
Like this:
/*
var model = AutoMap.AssemblyOf<MyDb>()
.Where(t => t.Namespace.StartsWith("MyDb.Tables"))
.Conventions.AddFromAssemblyOf<MyDb>();
*/
protected static AutoPersistenceModel CreateMappings()
{
//return new AutoPersistenceModel().AddMappingsFromAssemblyOf<MyDB.Tables.T_Admin>();
return new AutoPersistenceModel().AddMappingsFromAssemblyOf<MyDb.Tables.T_Admin>()
.Where(t => t.Namespace == "MyDb.Tables");
}
private static ISessionFactory CreateMsSqlSessionFactory()
{
//AutoPersistenceModel model = CreateAutoMappings();
AutoPersistenceModel model = CreateMappings();
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c
//.Server("MYCOMPUTER\\SQLEXPRESS")
.Server("localhost")
//.Database("testdb")
.Database("nhDMS")
.Username("TableCreatorWebServices")
.Password(DB.Tools.Cryptography.AES.DeCrypt("AES_ENCRYPTED_PW"))))
//.Mappings(m => m.FluentMappings.AddFromAssemblyOf<SsoToken>())
.Mappings(m =>
{
m.AutoMappings.Add(model);
m.FluentMappings.Conventions.Setup(x =>
{
//x.AddFromAssemblyOf<MyDb.Tables.T_Admin>();
x.Add(FluentNHibernate.Conventions.Helpers.AutoImport.Always()); // AutoImport.Never
}); // End FluentMappings.Conventions.Setup
}
) // End Mappings
.ExposeConfiguration(BuildSchema) // BuildSchema function call...
.BuildSessionFactory();
} // End Function CreateMsSqlSessionFactory
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