Fluent NHibernate Automap 加入子类设置 key

发布于 2024-07-22 17:16:40 字数 1162 浏览 8 评论 0原文

当在流畅的 nhibernate 中自动映射连接的子类时,我不知道如何为连接的子类提供主键。

public class Address:Entity {
    public virtual string Address1 { get; set; }
    public virtual string Address2 { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string Zip { get; set; }
    public virtual string Phone { get; set; }
    public virtual string Fax { get; set; }
    public virtual IList<Location> Locations { get; set; }
}

public class Location:Address {
    public virtual Address BillingAddress { get; set; }
    public virtual string OfficeHours { get; set; }
    public virtual string PatientAgeRestrictions { get; set; }
    public virtual bool WheelchairAccess { get; set; }
    public virtual string ContactPerson { get; set; }
    public virtual string ContactEmail { get; set; }
    public virtual string ContactPhone { get; set; }
    public virtual string ContactFax { get; set; }
    public virtual string TaxId { get; set; }
}

我希望 Location 有它自己的 id“location_ id”和它自己的序列。 然后我希望通过 address_id 列映射到地址。

现在它正在生成以“addressid”为主键的位置,这不是我想要的。 如何通过自动映射更改此设置?

When automapping a joined subclass in fluent nhibernate, I can't figure out how to give the joined subclass a primary key.

public class Address:Entity {
    public virtual string Address1 { get; set; }
    public virtual string Address2 { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string Zip { get; set; }
    public virtual string Phone { get; set; }
    public virtual string Fax { get; set; }
    public virtual IList<Location> Locations { get; set; }
}

public class Location:Address {
    public virtual Address BillingAddress { get; set; }
    public virtual string OfficeHours { get; set; }
    public virtual string PatientAgeRestrictions { get; set; }
    public virtual bool WheelchairAccess { get; set; }
    public virtual string ContactPerson { get; set; }
    public virtual string ContactEmail { get; set; }
    public virtual string ContactPhone { get; set; }
    public virtual string ContactFax { get; set; }
    public virtual string TaxId { get; set; }
}

I want Location to have it's own id "location_ id" with it's own sequence. Then I want that mapped to address through an address_id column.

Right now it's generating the location with "addressid" as the primary key, which isn't what I want. How do I change this with the automapping?

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

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

发布评论

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

评论(1

心的憧憬 2024-07-29 17:16:40

我不确定您是否存在加入子类关系。 也就是说,根据定义,连接的子类与其父类具有相同的 ID。 例如,您可能在数据库中存储了一个 Person 实体,用于存储姓名/年龄等通用“人员”信息,然后将一个 Employee 子类实体存储在不同的表并保存职位、工资和就业日期等数据。 因此,EmployeePerson 的子类型,要获取完整的“Employee-Person”对象,您必须在主键上连接两个表(例如 SELECT * FROM Employee INNER JOIN Person ON Employee.Employee_id = Person.Person_id)。

确定这里的关系模型吗? Location 真的是 Address 的子类型吗? 从你的财产名称推断一下,在我看来,这不是你想要的。 看起来您可能在 AddressOrganization 之间存在多对多(也就是说,同一地址可能有许多“组织”,并且“组织”可能有多个地址),并在特定地址有该组织的“联系人”。 在这种情况下,您应该映射“组织”、“联系人”以及定义 Address 和“组织”之间关系的另一个实体。

I'm not sure you have a joined-subclass relationship. That is, by definition a joined subclass has the same ID as its parent class. For example, you might have a Person entity stored in your database for generic "people" information like name/age/etc and then an Employee subclass entity which is stored in a different table and holds data like position, salary, and dates of employment. So an Employee is a subtype of Person and to get the full "Employee-Person" object, you must join the two tables on their primary keys (e.g. SELECT * FROM Employee INNER JOIN Person ON Employee.Employee_id = Person.Person_id).

Are you sure about your relational model here? Is Location truly a subtype of Address? Inferring a bit from your property names, it seems to me that this is not what you intend. It seems like you probably have a many-to-many between an Address and an Organization (that is, there may be many "organizations" at the same address and an "organization" may have many addresses), with a "contact person" for the organization at a specific address. In which case you should map "organization", "contact", and another entity that defines the relationship between Address and "organization".

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