使用 UseOverridesFromAssemblyOf 进行自动映射不会调用基类的重写类
我正在使用流畅的 nHibernate 自动映射,非常简单,就像这样:
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c
.Server("(local)\\sql2008")
.Database("nHibernate_test")
.TrustedConnection()))
.Mappings(m => m.AutoMappings.Add(
AutoMap.AssemblyOf<Domain.Airport>(cfg)
.UseOverridesFromAssemblyOf<ReaderMappingOverride>()
))
我的重写类是这样的:
public class ReaderMappingOverride : IAutoMappingOverride<Domain.Reader>
{
public void Override(AutoMapping<Domain.Reader> mapping)
{
//use the reader ID as identifier of the class, instead of the ID field defined in superclass Entity
mapping.IgnoreProperty(r => r.Id);
mapping.Id(r => r.ReaderNumber);
}
}
其中 Reader 是一个抽象基类。 如果我为每个子类使用单独的重写类,它就可以正常工作。 有什么方法可以定义抽象类的所有子类的重写吗?
谢谢,
强尼
i'm using automapping with fluent nHibernate, very simply, like so:
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c
.Server("(local)\\sql2008")
.Database("nHibernate_test")
.TrustedConnection()))
.Mappings(m => m.AutoMappings.Add(
AutoMap.AssemblyOf<Domain.Airport>(cfg)
.UseOverridesFromAssemblyOf<ReaderMappingOverride>()
))
my overriding classes are something like that:
public class ReaderMappingOverride : IAutoMappingOverride<Domain.Reader>
{
public void Override(AutoMapping<Domain.Reader> mapping)
{
//use the reader ID as identifier of the class, instead of the ID field defined in superclass Entity
mapping.IgnoreProperty(r => r.Id);
mapping.Id(r => r.ReaderNumber);
}
}
where Reader is an abstract base-class.
if I use a seperate overriding classes for each sub-class it works OK.
Is there any way to define the overriding for all subclasses of the abstract class?
thanks,
Jhonny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,刚刚回答了我自己的问题-
我的问题是我试图将从 Reader 类开始的层次结构映射到一个表中。但自动映射会自动忽略所有抽象类。我所做的只是将其添加到配置部分:
并将其添加到我的配置类中
(顺便说一句,Fluent nHibernate 站点中给出的示例使用了 .net 3.5 中不存在的方法“type.In(...”)。 .)
效果很好。
希望这有帮助...
ok, just answered my own question-
my problem was that i was trying to map a heirarchy which started with the Reader class, into a single table. but auto-mapping automatically ignores all abstract classes. what i did was just add this to the configuration section:
and this to my configuration class
(BTW, the example given in Fluent nHibernate's site uses the method "type.In(..." which does not exist in .net 3.5...)
that worked fine.
hopes this helps...