FluentNHibernate - 自动映射忽略属性 [英] FluentNHibernate - Automapping ignore property
问题描述
我有一个基类,其中包含一个名为IsDirty的属性。这用于域模型,不是数据库表中的列。
使用自动映射时,流利的nhibernate会尝试将此列添加到表中。一种解决这个问题的方法是在automapping设置中放置 .ForTypesThatDeriveFrom< Address>(p => p.IgnoreProperty(x => x.IsDirty))
/ p>
问题是,我的所有实体都会这样做,有没有办法在不必为每个实体添加此行的情况下声明?如果我把 .ForTypesThatDeriveFrom< Entity>(p => p.IgnoreProperty(x => x.IsDirty))
,那么当试图将Entity转换为地址。
我也有实体设置为基本类型。
在此先感谢, 然后你的流畅配置看起来像这样: / b> I have a base class that contains a property called IsDirty. This is used for the domain model and is not a column in the database table. When using automapping, fluent nhibernate tries to add this column to the table. A way to fix this is to put The problem is, all my entities will do this, is there a way to state this without have to add this line for every entity? If I put I also have entity set as the base type. Thanks in advance,
JT You create a class derived from Like so: and then your fluent configuration will look something like:
这篇关于FluentNHibernate - 自动映射忽略属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
JT创建一个从 DefaultAutomappingConfiguration
派生的类,然后重载
pre $ public class AutoMapConfiguration:DefaultAutomappingConfiguration
{
private static readonly IList< string> IgnoredMembers =新列表< string> {IsNew,IsDeleted};
public override bool ShouldMap(成员)
{
return base.ShouldMap(member)&& !IgnoredMembers.Contains(member.Name);
$ p
流利的.Configure()
//数据库设置
.Mappings(m => {
m.AutoMappings.Add(yourMappingAssembly,new AutoMapConfiguration())
});
.ForTypesThatDeriveFrom<Address>(p => p.IgnoreProperty(x => x.IsDirty))
in the automapping setup..ForTypesThatDeriveFrom<Entity>(p => p.IgnoreProperty(x => x.IsDirty))
, then I get an error trying to convert Entity to Address.DefaultAutomappingConfiguration
and override the ShouldMap(Member member)
method.public class AutoMapConfiguration : DefaultAutomappingConfiguration
{
private static readonly IList<string> IgnoredMembers = new List<string> {"IsNew", "IsDeleted"};
public override bool ShouldMap(Member member)
{
return base.ShouldMap(member) && !IgnoredMembers.Contains(member.Name);
}
}
Fluently.Configure()
// Database settings
.Mappings(m => {
m.AutoMappings.Add(yourMappingAssembly, new AutoMapConfiguration())
});