Fluent NHibernate Automap 加入子类设置 key
当在流畅的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否存在加入子类关系。 也就是说,根据定义,连接的子类与其父类具有相同的 ID。 例如,您可能在数据库中存储了一个
Person
实体,用于存储姓名/年龄等通用“人员”信息,然后将一个Employee
子类实体存储在不同的表并保存职位、工资和就业日期等数据。 因此,Employee
是Person
的子类型,要获取完整的“Employee-Person”对象,您必须在主键上连接两个表(例如SELECT * FROM Employee INNER JOIN Person ON Employee.Employee_id = Person.Person_id
)。您确定这里的关系模型吗?
Location
真的是Address
的子类型吗? 从你的财产名称推断一下,在我看来,这不是你想要的。 看起来您可能在Address
和Organization
之间存在多对多(也就是说,同一地址可能有许多“组织”,并且“组织”可能有多个地址),并在特定地址有该组织的“联系人”。 在这种情况下,您应该映射“组织”、“联系人”以及定义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 anEmployee
subclass entity which is stored in a different table and holds data like position, salary, and dates of employment. So anEmployee
is a subtype ofPerson
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 ofAddress
? 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 anAddress
and anOrganization
(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 betweenAddress
and "organization".