2016-05-30 56 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")));