【发布时间】:2015-08-09 17:32:47
【问题描述】:
我在 EF Core 数据模型中使用我自己的类的属性。
public class Currency
{
public string Code { get; set; }
public string Symbol { get; set; }
public string Format { get; set; }
}
[ComplexType]
public class Money
{
public int? CurrencyID { get; set; }
public virtual Currency Currency { get; set; }
public double? Amount { get; set; }
}
public class Rate
{
public int ID { get; set; }
public Money Price = new Money();
}
我的问题是,当我尝试创建迁移时,EF Core 报告错误。
Microsoft.Data.Entity.Metadata.ModelItemNotFoundException: The entity type 'RentABike.Models.Money' requires a key to be defined.
如果我声明一个键,则会为“Money”创建一个单独的表,这不是我想要的。
有没有办法在 EF Core 中使用 ComplexType 并将其全部放入一个表中?
【问题讨论】:
标签: asp.net-core-mvc entity-framework-core