简体   繁体   English

如何告诉Fluent NHibernate不要映射类属性

[英]How to tell Fluent NHibernate not to map a class property

I have a class that is mapped in fluent nhibernate but I want one of the classes properties to be ignored by the mapping. 我有一个以流畅的nhibernate映射的类,但我希望映射忽略其中一个类属性。

With class and mapping below I get this error: 使用下面的类和映射我得到此错误:

The following types may not be used as proxies: iMasterengine.Data.Model.Calendar: method get_HasEvents should be virtual 以下类型不能用作代理:iMasterengine.Data.Model.Calendar:方法get_HasEvents应该是虚拟的

//my class
public class Calendar : IEntity {
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }
    public virtual string SiteId { get; set; }
    public virtual IList<CalendarEvent> Events { get; set; }
    //ignore this property
    public bool HasEvents { get { return Events.Count > 0; } }
}

//my mapping
public class CalendarMap : ClassMap<Calendar> {
    public CalendarMap() {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.SiteId);
        HasMany(x => x.Events).Inverse();
        //what do I put here to tell nhibernate
        //to ignore my HasEvents property?
    }
}

You can just make HasEvents virtual in the class: 您可以在类中创建HasEvents 虚拟

public virtual bool HasEvents { get { return Events.Count > 0; } }

You don't need to add anything to the mappings. 您不需要向映射添加任何内容。

You only need to tell fluent to ingore a property if you are using Auto Mapping, which I don't think you are. 如果您使用自动映射,我只需要告诉流利的内容,我认为您不是。

map.IgnoreProperty(p => p.What);

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

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