2016-05-30 74 views
1

我想将Operationfinancial映射为Operation的联合子类。这个模型与我发现的例子的不同之处在于两者都使用复合键。如何使用复合键映射联合子类

操作图。

public class OperationMap : ClassMapping<Operation> 
    { 
     public OperationMap() 
     { 
      this.Table("ECM_OPE_Operation"); 

      this.ComponentAsId(
      x => x.Id, compAsId => 
      { 
       compAsId.Property(x => x.Id, m => { m.Column("Id"); m.NotNullable(true); }); 
       compAsId.Property(x => x.EventId, m => { m.Column("EventId"); m.NotNullable(true); }); 
      }); 

      this.Property(x => x.CreatedOn, map => map.NotNullable(true)); 
     } 
    } 

OperationFinancialMap。

public class OperationfinancialMap : JoinedSubclassMapping<OperationFinancial>, IEntityMap 
    { 
     public OperationfinancialMap() 
     { 
     this.Table("ECM_OFI_OperationFinancial"); 
     this.Key(m => 
      { 
       m.Column("Id"); 
       m.Column("EventId"); 
      }); 
     this.Property(x => x.Quantity, map => map.NotNullable(true)); 
     this.Property(x => x.Amount); 
    } 
    } 

但是当我运行我有这个错误

外键(FK3EDDC7CF4D8FE893:ECM_OFI_OperationFinancial [事件ID]))必须具有相同的号码作为引用的主键列(ECM_OPE_Operation [ID,EVENTID ])

任何想法?

回答

0

这里是解决

Key(key => key.Columns(c => c.Name("Id"), c => c.Name("EventId")));