如何告诉 Fluent NHibernate 不要映射类属性
我有一个在 Fluent nhibernate 中映射的类,但我希望映射忽略其中一个类属性。
使用下面的类和映射,我收到此错误:
以下类型不能用作代理: 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?
}
}
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?
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需在类中创建
HasEvents
虚拟:您不需要向映射添加任何内容。
如果您使用自动映射,您只需要告诉 Fluent 忽略属性,我认为您不需要。
You can just make
HasEvents
virtual in the class: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.
您还可以使用
AutoMapper.Configuration.Annotations
命名空间中的[Ignore]
属性。将其直接放在属性声明上方。You can also use the
[Ignore]
attribute in theAutoMapper.Configuration.Annotations
namespace. Place it directly above the property declaration.