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.
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
//my class
public class Calendar : IEntity {
public virtual int Id { get; private set; }
public virtual string Name { get; set; }
public virtual strin开发者_如何学编程g 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:
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);
精彩评论