【问题标题】:Mapping with extendend class与扩展类的映射
【发布时间】:2012-09-18 20:53:48
【问题描述】:

我正在使用 NHibernate 和 ConfORM 来映射我的域实体。

假设以下类:

public class Event {
    public virtual Guid Id { get; set; }
    public virtual string Title { get; set; }
    public virtual bool Active { get; set; }
}

public class EventA : Event {
    public virtual string PropertyA { get; set; }
}

public class EventB : Event {
    public virtual string PropertyB { get; set; }
}

我需要不重复派生类中的 NHibernate 表字段,而是使用基类,如图所示。

我的 ConfORM 设置:

var domainAssembly = typeof(Event).Assembly;
var domainEntities = from t in domainAssembly.GetTypes() where t==typeof(Event) select t;
var orm = new ObjectRelationalMapper();
orm.Patterns.Sets.Add(new UseSetWhenGenericCollectionPattern());
orm.Patterns.PoidStrategies.Add(new ConfOrm.Patterns.IdentityPoidPattern());
orm.TablePerConcreteClass(domainEntities);
var patternsAppliers = new CoolPatternsAppliersHolder(orm);
var mapper = new Mapper(orm, patternsAppliers);
[...]

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: c# nhibernate orm conform


    【解决方案1】:

    orm.TablePerConcreteClass(domainEntities);orm.TablePerClass(domainEntities); 交换,这将创建

    Event
    -----
    PK | Id
    
    EventA
    -----
    PK,FK | EventId
    

    因为 EventA 中不需要单独的 Id 列

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-09
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 2022-01-22
      相关资源
      最近更新 更多