具有 Fluent Nhibernate 的嵌套子类

发布于 2024-08-30 18:47:20 字数 123 浏览 1 评论 0原文

我已经看到了如何使用旧的子类语法执行此操作的示例,但没有看到使用较新的 : SubclassMap 语法的示例。

基本上,我的表中有多个鉴别器,需要弄清楚如何使用 FNH 来做到这一点。

谢谢, 山姆

I've seen examples of how to do this with the old subclass syntax, but none with the newer : SubclassMap syntax.

Basically, I have multiple discriminators in a table and need to figure out how to do this with FNH.

Thanks,
Sam

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

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

发布评论

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

评论(1

贪了杯 2024-09-06 18:47:20

我们有一个基类 User 和许多派生类,如学习者、评估者、经理、管理员等。

这里是 UserMap

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        this.Id(x => x.Id);

        this.Map(x => x.Active);

        this.Component(
            x => x.Address,
            m =>
            {
                m.Map(x => x.Address1).Length(512);
                m.Map(x => x.Address2);
                m.Map(x => x.Address3);
                m.Map(x => x.Address4);
                m.Map(x => x.City);
                m.Map(x => x.County);
                m.Map(x => x.PostCode);
                m.References(x => x.Country);
            });

        this.References(x => x.CreatedBy);

        this.Map(x => x.CreatedDate).Not.Nullable();

        this.Map(x => x.DeletedDate);

        this.References(x => x.DeletedBy);

        this.Map(x => x.Email);

        this.Map(x => x.Fax);

        this.Map(x => x.FirstName);

        this.References(x => x.Gender);

        this.Map(x => x.LastName);

        this.Map(x => x.LoginName).UniqueKey("ui_loginName").Not.Nullable();

        this.Map(x => x.MiddleName);

        this.Map(x => x.Password);

        this.DiscriminateSubClassesOnColumn("className").Length(64);
    }
}

和 Manager 的示例

 public class ManagerMap : SubclassMap<Manager>
{
    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="ManagerMap"/> class.
    /// </summary>
    public ManagerMap()
    {
        this.HasManyToMany(x => x.Organisation)
            .ParentKeyColumn("userId")
            .ChildKeyColumn("organisationId")
            .Table("UserOrganisations");

        this.HasMany(x => x.Learners)
            .KeyColumn("managerId")
            .AsBag();
    }

    #endregion
}

希望对您有所帮助。

We have a base class User and many derived classes from that as Learners, Assessors, Managers, Admins etc.

here is the UserMap

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        this.Id(x => x.Id);

        this.Map(x => x.Active);

        this.Component(
            x => x.Address,
            m =>
            {
                m.Map(x => x.Address1).Length(512);
                m.Map(x => x.Address2);
                m.Map(x => x.Address3);
                m.Map(x => x.Address4);
                m.Map(x => x.City);
                m.Map(x => x.County);
                m.Map(x => x.PostCode);
                m.References(x => x.Country);
            });

        this.References(x => x.CreatedBy);

        this.Map(x => x.CreatedDate).Not.Nullable();

        this.Map(x => x.DeletedDate);

        this.References(x => x.DeletedBy);

        this.Map(x => x.Email);

        this.Map(x => x.Fax);

        this.Map(x => x.FirstName);

        this.References(x => x.Gender);

        this.Map(x => x.LastName);

        this.Map(x => x.LoginName).UniqueKey("ui_loginName").Not.Nullable();

        this.Map(x => x.MiddleName);

        this.Map(x => x.Password);

        this.DiscriminateSubClassesOnColumn("className").Length(64);
    }
}

and an example of Manager

 public class ManagerMap : SubclassMap<Manager>
{
    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="ManagerMap"/> class.
    /// </summary>
    public ManagerMap()
    {
        this.HasManyToMany(x => x.Organisation)
            .ParentKeyColumn("userId")
            .ChildKeyColumn("organisationId")
            .Table("UserOrganisations");

        this.HasMany(x => x.Learners)
            .KeyColumn("managerId")
            .AsBag();
    }

    #endregion
}

Hope that will help you.

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