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

发布于 2024-11-16 07:42:39 字数 882 浏览 1 评论 0原文

我有一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相思碎 2024-11-23 07:42:39

您只需在类中创建 HasEvents 虚拟

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

您不需要向映射添加任何内容。

如果您使用自动映射,您只需要告诉 Fluent 忽略属性,我认为您不需要。

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.

初见终念 2024-11-23 07:42:39
map.IgnoreProperty(p => p.What);
map.IgnoreProperty(p => p.What);
云胡 2024-11-23 07:42:39

您还可以使用 AutoMapper.Configuration.Annotations 命名空间中的[Ignore] 属性。将其直接放在属性声明上方。

You can also use the [Ignore] attribute in the AutoMapper.Configuration.Annotations namespace. Place it directly above the property declaration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文