如何分辨功能NHibernate没有映射类属性 [英] How to tell Fluent NHibernate not to map a class property
本文介绍了如何分辨功能NHibernate没有映射类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用流利的NHibernate映射一类,但我想在类的属性之一,由映射被忽略。
使用类和映射下面我得到这个错误:
<强> *以下类型可能不能用作代理:
iMasterengine.Data.Model.Calendar:方法get_HasEvents应该是虚拟的*
//我的课
公共类日历:IEntity {
公共虚拟INT标识{搞定;私人集; }
公共虚拟字符串名称{;组; }
公共虚拟字符串SITEID {搞定;组; }
公共虚拟的IList&LT; CalendarEvent&GT;活动得到{;组; }
//忽略此属性
公共BOOL HasEvents {{返回Events.Count&GT; 0; }}
}//我的映射
公共类CalendarMap:ClassMap&LT;日历和GT; {
公共CalendarMap(){
ID(X =&GT; x.Id);
地图(X =&GT; x.Name);
地图(X =&GT; x.SiteId);
的hasMany(X =&GT; x.Events).Inverse();
//我该怎么把这里要告诉NHibernate的
//不理我HasEvents的财产?
}
}
解决方案
map.IgnoreProperty(P =&GT; p.What);
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 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?
}
}
解决方案
map.IgnoreProperty(p => p.What);
这篇关于如何分辨功能NHibernate没有映射类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文