NHibernate:使用单个表的接口映射复杂对象
我正在尝试映射一个具有接口(INameTypeInfo)属性的复合对象。该接口由 2 个类(PersonNameInfo 和 CompanyNameInfo)实现。所有这三个结构的信息都在同一个表中。
该对象如下所示:
public class Name : Entity
{
public virtual string FirstName {get; set;}
public virtual string LastName {get; set;}
public virtual INameTypeInfo NameTypeInfo {get; set;}
etc...
}
其他对象如下所示:
public class PersonNameTypeInfo()
{
public string SSN {get; set;}
public string AKAFistName {get; set;}
public string AKALastName {get; set;}
etc...
}
public class CompanyNameTypeInfo()
{
public string FederalIDNumber {get; set;}
public string AKAName {get; set;}
etc...
}
数据库表如下所示:
Names
- FirstName
- LastName
- AKAFistName <--- ---当信息是公司信息时,该字段用于 AKAName
- AKALastName
- SSN
- FID
- CompanyContact
另请注意:Name 对象也会被其他对象继承,如 Party:Name、Provider:Name 等...
数据库是遗留数据库已经在使用了。
任何关于如何用 flutter 映射它的例子都会很有帮助。
谢谢。
I am trying to map a composite object that has a property with an interface (INameTypeInfo). This interface is implemented by 2 classes (PersonNameInfo and CompanyNameInfo). The information for all three of these structures in the same table.
The object looks like this:
public class Name : Entity
{
public virtual string FirstName {get; set;}
public virtual string LastName {get; set;}
public virtual INameTypeInfo NameTypeInfo {get; set;}
etc...
}
The other objects look like this:
public class PersonNameTypeInfo()
{
public string SSN {get; set;}
public string AKAFistName {get; set;}
public string AKALastName {get; set;}
etc...
}
public class CompanyNameTypeInfo()
{
public string FederalIDNumber {get; set;}
public string AKAName {get; set;}
etc...
}
The db table looks like this:
Names
- FirstName
- LastName
- AKAFistName <------When the information is for a company, this field is used for AKAName
- AKALastName
- SSN
- FID
- CompanyContact
Also note: The Name object is also inherited by other objects, like Party:Name, Provider:Name, etc...
The database is a legacy db that is already in use.
Any example of how I could map this with fluent would be helpful.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你加载这些人时,那么你也可以使用公司。所以当你说
Person.company.name 它将获取名称,如果您在处理公司的人员中更改任何内容,则当您将其提交回数据库时,Hibernate 会级联所有更改。
也许这不是你的问题,而只是一个值得深思的问题。
但如果你想让它们成为一个复合键,你可以创建第三个对象示例,
而不是在一个人内部建立公司。当您检索组织时,您会同时获得个人和公司 DAO
when you load th persons, then you also can use the company. So when you say
Person.company.name it will get the name, and if you change anything within the person that deals with company Hibernate cascades all the changes when you commit it back to the database.
Maybe thats not you question, but just a food for thought.
but if you want to make them a composite key you can make a third object example
rather than having company inside a person. when you retrieve organization you get both person and company DAO