NHibernate的配置问题 [英] NHibernate Configuration Problem
问题描述
任何人可以帮助我。我的目标是,始终使用相同的数据库。通过我,它会覆盖我的所有数据。我得到这个错误:创建一个SessionFactory使用了无效的或不完整的配置。检查PotentialReasons集合,的InnerException了解更多详情。
我的code样子:
使用FluentNHibernate;运用
NHibernate的;运用
FluentNHibernate.Cfg;运用
FluentNHibernate.Cfg.Db;运用
FluentNHibernate.Automapping;运用
NHibernate.Cfg;运用
NHibernate.Tool.hbm2ddl;运用
NHibernate.Criterion;运用
FluentNhibernateTest;运用
FluentNHibernate.Mapping;运用
MMAdminPfyn.MappingFiles;
命名空间FluentNhibernateTest {
公共密封类FluentNHibernateHelper
{
私有静态ISessionFactory SessionFactory的;公共静态ISessionFactory的GetInstance()
{
如果(SessionFactory的== NULL)
{
SessionFactory的= BuildSessionFactory();
}
返回SessionFactory的;
} 私有静态ISessionFactory BuildSessionFactory()
{ 返回Fluently.Configure()
.Database(PostgreSQLConfiguration.PostgreSQL82
.ConnectionString(C =以及c
。主持人(localhost的)
.Port(5432)
.Database(blablabla)
.Username(blablabla)
。密码(blablabla)))
.Mappings(M => m.FluentMappings
.AddFromAssemblyOf< AdresseMap>()
.AddFromAssemblyOf< PersonMap>()
.AddFromAssemblyOf< InstitutionMap>()
.AddFromAssemblyOf< LiteraturMap>()
.AddFromAssemblyOf< KategorieMap>()
.AddFromAssemblyOf< MediaDateiMap>()
)
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
} 私有静态无效BuildSchema(配置配置)
{
新的SchemaExport(配置).Create(真实的,
TRUE);
}
}}
块引用>解决方案此问题是与该位:
.Mappings(M = GT; m.FluentMappings
.AddFromAssemblyOf< AdresseMap>()
.AddFromAssemblyOf< PersonMap>()
.AddFromAssemblyOf< InstitutionMap>()
.AddFromAssemblyOf< LiteraturMap>()
.AddFromAssemblyOf< KategorieMap>()
.AddFromAssemblyOf< MediaDateiMap>()
)https://github.com/jagregory/fluent-nhibernate/报价维基/流利的配置,
如果您在您的应用程序是专门使用的情况是
流利的映射,那么这就是你的配置。
块引用>这意味着你要赠送的组装的其中包含的类;你在这里做等于告诉流利,地图,其中包含这个类的程序集。
VAR SessionFactory的= Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(M =>
m.FluentMappings
.AddFromAssemblyOf< YourEntity>())
.BuildSessionFactory();试试这个吧。
.Mappings(M = GT; m.FluentMappings.AddFromAssemblyOf< AdresseMap>());
Can anybody help me. My aim is, to use always the same database. By me it overrides all my data. I get this error: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
My Code look like:
using FluentNHibernate; using NHibernate; using FluentNHibernate.Cfg; using FluentNHibernate.Cfg.Db; using FluentNHibernate.Automapping; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; using NHibernate.Criterion; using FluentNhibernateTest; using FluentNHibernate.Mapping; using MMAdminPfyn.MappingFiles;
namespace FluentNhibernateTest { public sealed class FluentNHibernateHelper { private static ISessionFactory sessionFactory;
public static ISessionFactory GetInstance() { if (sessionFactory == null) { sessionFactory = BuildSessionFactory(); } return sessionFactory; } private static ISessionFactory BuildSessionFactory() { return Fluently.Configure() .Database(PostgreSQLConfiguration.PostgreSQL82 .ConnectionString(c => c .Host("localhost") .Port(5432) .Database("blablabla") .Username("blablabla") .Password("blablabla"))) .Mappings(m => m.FluentMappings .AddFromAssemblyOf<AdresseMap>() .AddFromAssemblyOf<PersonMap>() .AddFromAssemblyOf<InstitutionMap>() .AddFromAssemblyOf<LiteraturMap>() .AddFromAssemblyOf<KategorieMap>() .AddFromAssemblyOf<MediaDateiMap>() ) .ExposeConfiguration(BuildSchema) .BuildSessionFactory(); } private static void BuildSchema(Configuration config) { new SchemaExport(config).Create(true,
true); } } }
解决方案This problem is with this bit:
.Mappings(m => m.FluentMappings .AddFromAssemblyOf<AdresseMap>() .AddFromAssemblyOf<PersonMap>() .AddFromAssemblyOf<InstitutionMap>() .AddFromAssemblyOf<LiteraturMap>() .AddFromAssemblyOf<KategorieMap>() .AddFromAssemblyOf<MediaDateiMap>() )
Quoted from https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-configuration,
If you're in the situation where your application is exclusively using fluent mappings, then this is the configuration for you.
which means that you are giving the assembly which contains the classes; what you're doing here is equal to telling Fluent, "Map the assembly which contains this class."
var sessionFactory = Fluently.Configure() .Database(SQLiteConfiguration.Standard.InMemory) .Mappings(m => m.FluentMappings .AddFromAssemblyOf<YourEntity>()) .BuildSessionFactory();
Try this instead.
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<AdresseMap>());
这篇关于NHibernate的配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!