Fluent NHibernate 自动映射配置抛出模糊错误
我正在尝试 Fluent NHibernate 的自动映射功能,当我尝试将其移动到自动映射时,在构建 SessionFactory
时使用显式 ClassMap
配置的相同代码失败。
这是代码:
public static ISessionFactory GetSessionFactory()
{
if (_sessionFactory == null)
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DB")))
// It works with the following:
// .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Customer>())
// It fails with this:
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Customer>()))
.BuildSessionFactory();
return _sessionFactory;
}
我得到的错误是:
配置无效或不完整 创建时使用 会话工厂。检查潜在原因 集合,以及 InnerException 更多细节。
我得到 PotentialReasons
的 Count = 0
,内部异常与上面相同。
堆栈跟踪指的是:
在 FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 在 d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs 中:第 113 行
似乎我已经尝试了一切让它工作,而我最接近的是进行初始化当我尝试使用会话时,只是得到一个 Could not find persister for...
错误,我什至不记得如何做到这一点。
我正在使用带有 NHibernate 3.0、SQL 2008 数据库的 build #694。有什么想法我做错了吗?
I'm trying out the automapping capability of Fluent NHibernate, and the same code that worked with explicit ClassMap
configurations is failing when building the SessionFactory
when I try to move it to automapping.
Here's the code:
public static ISessionFactory GetSessionFactory()
{
if (_sessionFactory == null)
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DB")))
// It works with the following:
// .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Customer>())
// It fails with this:
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Customer>()))
.BuildSessionFactory();
return _sessionFactory;
}
The error I get is:
An invalid or incomplete configuration
was used while creating a
SessionFactory. Check PotentialReasons
collection, and InnerException for
more detail.
I get Count = 0
for PotentialReasons
and the inner exception is the same as above.
The stacktrace refers to:
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 113
It seems like I've tried everything to get it to work, and the closest I came was to have the initialization work only to get a Could not find persister for...
error when I tried to use the session, and I don't even remember how I was able to get that to happen.
I'm using the build #694 with NHibernate 3.0, SQL 2008 database. Any ideas what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个愚蠢的错误,阿利奥斯塔的评论帮助我找到了。我有一个枚举类型,它作为整数存储在数据库中,NHibernate 对此感到窒息。我在设置中添加了一个 EnumConvention,如下所示:
这是枚举约定:
This was a dumb error that Aliostad's comment helped me find. I had an enum type that was stored as an integer in the database, and NHibernate was choking on that. I added an EnumConvention to the setup like this:
Here's that enum convention: