EF核心2.14将几个相同类型的对象映射到单个表

时间:2018-10-23 11:04:39

标签: c# entity-framework ef-core-2.0 ef-core-2.1

假设我们要保存付款给数据库

Public class Payment{

   protected Payment()
   {
   }

   Public string Id{get;set}
   Public Money Fee {get; set;}
   Public Money Amount {get; set;}
}

Public class Money{
   public decimal Amount{get; set;}
   public string Description{get;set} 
}    

现在我在映射中遇到的错误是:

无法确定类型为“钱”的导航属性“付款。金额”表示的关系。要么手动配置关系,要么使用“ [NotMapped]”属性或“ OnModelCreating”中的“ EntityTypeBuilder.Ignore”忽略此属性。

 public void Configure(EntityTypeBuilder<Payment> builder)
        {
           //Do some smart mapping here, rename for Fee money object only Amount to fee & ignore description
            builder.OwnsOne(
               a => a.Fee
            );
        }

如果我在Payment类中只有一个Money对象,一切都会很好

0 个答案:

没有答案