Fluent NHibernate - 如何使用枚举器来识别子类?

发布于 2024-08-19 20:26:01 字数 877 浏览 2 评论 0原文

我正在尝试映射以下类:

public abstract class ScheduleType
{
    public virtual int Id { get; set; }
    public virtual TypeDiscriminatorEnum Discriminator { get; set; }
}

public class DerivedScheduleType : ScehduleType
{
    public virtual bool MyProperty { get; set; }
}



public class ScheduleTypeMap : ClassMap<ScheduleType>
{
    public ScheduleTypeMap()
    {
        Id(p => p.Id);
        Map(p => p.Discriminator).CustomType<TypeDiscriminatorEnum>().Not.Nullable();
    }
}

public class DerivedScheduleTypeMap : SubclassMap<DerivedScheduleType>
{
    public DerivedScheduleTypeMap()
    {
        //DiscriminatorValue(TypeDiscriminatorEnum.DerivedSchedule);
        Map(p => p.MyProperty);
    }
}

问题是 ScheduleType 上的查询与所有派生表连接以找到正确的表。

我需要一些东西来告诉 NHibernate 仅与代表正确子类的表连接。

有什么建议吗?

提前致谢!

Im trying to map the following classes:

public abstract class ScheduleType
{
    public virtual int Id { get; set; }
    public virtual TypeDiscriminatorEnum Discriminator { get; set; }
}

public class DerivedScheduleType : ScehduleType
{
    public virtual bool MyProperty { get; set; }
}



public class ScheduleTypeMap : ClassMap<ScheduleType>
{
    public ScheduleTypeMap()
    {
        Id(p => p.Id);
        Map(p => p.Discriminator).CustomType<TypeDiscriminatorEnum>().Not.Nullable();
    }
}

public class DerivedScheduleTypeMap : SubclassMap<DerivedScheduleType>
{
    public DerivedScheduleTypeMap()
    {
        //DiscriminatorValue(TypeDiscriminatorEnum.DerivedSchedule);
        Map(p => p.MyProperty);
    }
}

The problem is that queries on ScheduleType joins with all derived tables to find the right one.

I need something that says to NHibernate to join only with the table that represents the right subclass.

Any sugestions?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

国际总奸 2024-08-26 20:26:01

使用 DiscriminateSubClassesOnColumn("discriminator") 而不是 Map(p => p.Discriminator)

我不太确定你想要实现什么目标,因为你正在谈论加入其他表;鉴别器不与每个子类表一起使用,仅在每个类层次结构表中使用。

Use DiscriminateSubClassesOnColumn<TypeDiscriminatorEnum>("discriminator") instead of Map(p => p.Discriminator).

I'm not quite sure what you're trying to achieve though, because you're talking about joining other tables; discriminators aren't used with table-per-subclass, only in table-per-class-hierarchy.

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