简体   繁体   English

Nhibernate拦截器未获取基类的属性

[英]Nhibernate interceptors not picking up properties of base class

I'm converting from Fluent to Loquacious, and I've run in to an issue where my interceptors are not getting all the fields like I think they should. 我正在从Fluent转换为Loquacious,并且遇到了一个问题,即我的拦截器无法像我认为的那样获取所有字段。 If I look at the OnSave function 如果我看一下OnSave函数

public override Boolean OnSave(Object entity, Object id, Object[] state,
        String[] propertyNames, IType[] types)

and take a look at the propertyNames the only items in there are the items that were explicitly mapped in the mapping file (in the example this would just be ID, Start, and End). 并查看一下propertyNames,其中的唯一项是在映射文件中显式映射的项(在示例中,这将只是ID,Start和End)。

In my case though I have a base class which isn't mapped at all. 就我而言,尽管我有一个根本没有映射的基类。 Instead it's just contains properties that get filled out by the interceptors. 相反,它只包含被拦截器填充的属性。 This used to work in Fluent Nhibernate, but now that I've moved to Nhibernate 3.3 I can't get it to work anymore. 这曾经在Fluent Nhibernate中起作用,但是现在我移到Nhibernate 3.3中了,我再也无法使用它了。

My classes/mapping look something like this 我的课程/映射看起来像这样

public class BaseAuditEntity
{
  public virtual int ModifiedByUserID { get; set; }
  public virtual DateTime LastModifiedTime { get; set; }
}

public class Foo : BaseAuditEntity
{
  public virtual int ID { get; protected internal set; }
  public virtual DateTime Start { get; protected internal set; }
  public virtual DateTime End { get; protected internal set; }
}

public class FooMap: ClassMapping<Foo>
{
  Id(x => x.ID, m => m.column("fooID"));
  Property(x => x.Start, m => m.column("start"));
  Property(x => x.End, m => m.column("end"));
}

Any ideas of how to get this work? 关于如何进行这项工作的任何想法? I don't want to have to map this every class, and I didn't think I needed to map the BaseAuditEntity, at least with Fluent it wasn't needed. 我不想必须映射每个类,并且我也不认为我需要映射BaseAuditEntity,至少对于Fluent而言,不需要。

you could make a base mapping class 你可以做一个基本的映射类

public class BaseAuditEntityMapping<T> : ClassMapping<T> where T: BaseAuditEntity
{
    ManyToOne(x => x.ModifiedByUser);
    Property(x => x.LastModifiedTime);
}

public class FooMap: BaseAuditEntityMapping<Foo>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM