NHibernate:使用单个表的接口映射复杂对象

发布于 2024-12-01 12:22:38 字数 1101 浏览 5 评论 0原文

我正在尝试映射一个具有接口(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 技术交流群。

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

发布评论

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

评论(1

☆獨立☆ 2024-12-08 12:22:38
public class person
{

// this is the table for person 
   private String name;
   private String lastName;
   private Company company;


}


public class Company
{ 
  private string name;
  private string address;
  // more properties.
}

当你加载这些人时,那么你也可以使用公司。所以当你说
Person.company.name 它将获取名称,如果您在处理公司的人员中更改任何内容,则当您将其提交回数据库时,Hibernate 会级联所有更改。

也许这不是你的问题,而只是一个值得深思的问题。

但如果你想让它们成为一个复合键,你可以创建第三个对象示例,

public class  organization
{
  private person person;
  private company company;
}

而不是在一个人内部建立公司。当您检索组织时,您会同时获得个人和公司 DAO

public class person
{

// this is the table for person 
   private String name;
   private String lastName;
   private Company company;


}


public class Company
{ 
  private string name;
  private string address;
  // more properties.
}

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

public class  organization
{
  private person person;
  private company company;
}

rather than having company inside a person. when you retrieve organization you get both person and company DAO

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