Fluent NHibernate 没有自动映射和模式创建:我不知道出了什么问题
我不明白为什么 Fluent NHibernate 自动映射和模式生成不起作用。
我有这样的代码:
return Fluently
.Configure()
.Database
(
MsSqlConfiguration.MsSql2005.ConnectionString
(
c => c.FromConnectionStringWithKey("dataAccess")
)
)
.Mappings(config => config.AutoMappings.Add(AutoMap.Assembly(ObjectsAssembly, new ORMAutoMappingConfiguration())))
.ExposeConfiguration(config => new SchemaExport(config).Create(true, true))
.BuildSessionFactory()
.OpenSession();
并且:
public sealed class ORMAutoMappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Member member)
{
return member.DeclaringType.IsSubclassOf(typeof(DomainObject));
}
}
数据库和映射未创建。
“ObjectsAssembly”是一个属性,我看过它,我可以确定这是正确的程序集,并且它具有继承 DomainObject 的域对象。
另一件事是,在此过程中永远不需要自动映射配置类,FNH 不会调用 ShouldMap。
怎么了?
谢谢。
I can't figure out why Fluent NHibernate automapping and schema generation aren't working.
I've this code:
return Fluently
.Configure()
.Database
(
MsSqlConfiguration.MsSql2005.ConnectionString
(
c => c.FromConnectionStringWithKey("dataAccess")
)
)
.Mappings(config => config.AutoMappings.Add(AutoMap.Assembly(ObjectsAssembly, new ORMAutoMappingConfiguration())))
.ExposeConfiguration(config => new SchemaExport(config).Create(true, true))
.BuildSessionFactory()
.OpenSession();
And:
public sealed class ORMAutoMappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Member member)
{
return member.DeclaringType.IsSubclassOf(typeof(DomainObject));
}
}
The database and mappings aren't created.
"ObjectsAssembly" is a one got in a property, I've watched it and I could determine that this is the right assembly and it has domain objects inheriting DomainObject.
Another thing is automapping configuration class is never required in the process, ShouldMap isn't invoked by FNH.
What's wrong?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不能说你的自动映射有什么问题,但要使用你需要的模式生成
Can't say whats wrong with your automappings but to use Schema generation you need
可悲的是,这是一个很容易解决的问题!我正在重写 ShouldMap(Member) 而不是 ShouldMap(Type) 重载。
任何类型都将被映射,这是错误的,因为并非所有类型都是域对象。
我的域模型和数据库正在运行!
不管怎样,谢谢你。
Sadly, this was a very easy to solve problem! I was overriding ShouldMap(Member) instead of ShouldMap(Type) overload.
That's any type was going to be mapped, which is wrong because not all of them were domain objects.
I've my domain model and database working!
Thank you anyway.