C# 如何使用复合键映射连接的子类
我想将C# 如何使用复合键映射连接的子类,c#,nhibernate,C#,Nhibernate,我想将Operationfinancial映射为Operation的连接子类。这个模型与我发现的示例的不同之处在于两者都使用复合键 行动图 public class OperationMap : ClassMapping<Operation> { public OperationMap() { this.Table("ECM_OPE_Operation"); this.ComponentAsId
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));
}
}
公共类操作映射:类映射
{
公共运营地图()
{
此表(“ECM操作”);
这是一个组件(
x=>x.Id,compAsId=>
{
属性(x=>x.Id,m=>{m.Column(“Id”);m.NotNullable(true);});
属性(x=>x.EventId,m=>{m.Column(“EventId”);m.NotNullable(true);});
});
属性(x=>x.CreatedOn,map=>map.NotNullable(true));
}
}
运营财务图
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);
}
}
公共类操作FinancialMap:JoinedSubclass映射,IEntityMap
{
公共运营财务计划()
{
此表(“I_运营财务的ECM_”);
这个.Key(m=>
{
m、 列(“Id”);
m、 列(“事件ID”);
});
属性(x=>x.Quantity,map=>map.NotNullable(true));
此属性(x=>x.Amount);
}
}
但是当我跑的时候,我犯了这个错误
外键(FK3EDDC7CF4D8FE893:ECM_of i_OperationFinancial[EventId])必须与引用的主键(ECM_OPE_Operation[Id,EventId])具有相同的列数
有什么想法吗?这是解决方案
Key(key => key.Columns(c => c.Name("Id"), c => c.Name("EventId")));
这是解决办法
Key(key => key.Columns(c => c.Name("Id"), c => c.Name("EventId")));