【问题标题】:Fluent NHibernate Create entity mapping for overlapping entitiesFluent NHibernate 为重叠实体创建实体映射
【发布时间】:2015-06-20 11:36:14
【问题描述】:

例如。我的数据库中有两个表

NonResidentStudents - 列 studentID、studentname、ModeOfTransport

ResidentStudents - 列 studentID、studentname、DateOfJoiningHostel

studentID 和 studentName 是公共列,最后一列在两者之间不常见

由于某种原因,我无法更改这些表或定义一个公共主表并在子表中创建不常见的列。所以桌子结构是刚性的。

现在,当尝试使用 FLUENT NHIBERNATE(仅)为上述模式创建实体和映射时,我想知道是否可以为公共列定义某种公共实体和公共映射,并创建继承自的子实体共同实体。在子实体和映射类中,我将对不常见的列进行表示。任何人都可以分享如何做到这一点的代码。

【问题讨论】:

    标签: entity-framework inheritance fluent-nhibernate mapping entity


    【解决方案1】:

    我以前做过。

    普通类

    public class BaseMapping : ClassMap<EntityBase>{
    
        public BaseMapping ()
        {
            UseUnionSubclassForInheritanceMapping ();
            // All the rest of the mapping attributes
        }
    }
    

    对于将从基类继承的单个类,请执行以下操作:

    public class DepartmentMapping : SubclassMap<Department>
    {
        public DepartmentMapping ()
        {
            Abstract ();
            // Map all the unique attributes
        }
    }
    

    上面的代码将创建一个基于 Department 和 EntityBase 的类。它不会创建一个名为 EntityBase 的表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-26
      • 2011-07-07
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多