【问题标题】:Fluent NHibernate join table mappingFluent NHibernate 连接表映射
【发布时间】:2010-06-02 18:22:07
【问题描述】:

使用 Fluent N-Hibernate 对现有数据库进行逆向工程以映射到 N-Hibernate。

如何映射?

地址表

身份证
地址1
地址2

人员表

身份证
第一
最后

类型

身份证
类型名称

PersonAddress 表(一个人可以有家庭、公司等地址)

身份证

PersonId(来自人员表的 ID)

AddressId(地址表中的Id)

TypeId(来自类型查找表 HOME、BUSINESS 等的 ID。)

任何帮助都会很棒。谢谢

除了上面的映射之外,还有另一个棘手的问题。不知道绘制它有多容易。

宴会桌

身份证 Person Id 指向 Person

标识符表

身份证 派对 ID 类型 ID 标识符值

员工表

Employee Id 没有任何party 或person 表具有该表的外键。员工 ID 存储在 标识符表。所以例如标识符表用于存储不同类型的值。给定方的标识符可以是 DriverLicense、EmployeeId、SSN、信用卡号等,这可以是多个值。

示例标识符数据

Id、PartyId、TypeId、IdentifierValue

1、1、1、EMPLID-1234 2、2、1、EMPLID-4567 3、3、1、EMPLID-34354

我正在努力解决这个问题,但无法将其映射。

【问题讨论】:

    标签: nhibernate fluent-nhibernate nhibernate-mapping


    【解决方案1】:
    // this answer assumes you have functional Address, Person, Type, and PersonAddress objects.
    
    public class AddressMap : ClassMap<Address>
    {
      public AddressMap()
      {
        Id(x=>x.Id);
        Map(x=>x.Address1);
        Map(x=>x.Address2);
      }
    }
    
    public class PersonMap : ClassMap<Person>
    {
       public PersonMap()
       {
         Id(x=>x.Id);
         Map(x=>x.First);
         Map(x=>x.Last);
       }
    }
    
    public class TypeMap : ClassMap<Type>
    {
       public TypeMap()
       {
         Id(x=>x.Id);
         Map(x=>x.TypeName);
       }
    }
    
    public class PersonAddressMap : ClassMap<PersonAddress>
    {
       public PersonAddressMap()
       {
         Id(x=>x.Id);
         References(x=>x.Person, "PersonId");
         References(x=>x.Address, "AddressId");
         References(x=>x.Type, "TypeId");
       }
    }
    

    【讨论】:

    • 但这实际上并没有加入表,因此您的性能仍然会受到影响,因为它正在为每个子对象进行单独的查询。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 2012-04-03
    相关资源
    最近更新 更多