在Entity Framework Core中使用[ComplexType] [英] Using [ComplexType] in Entity Framework Core
本文介绍了在Entity Framework Core中使用[ComplexType]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在EF Core数据模型中使用自己的类的属性.
I'm using a property of my own class inside EF Core data model.
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报告一个错误.
My problem is that when I try to create a migration, EF Core reports a error.
Microsoft.Data.Entity.Metadata.ModelItemNotFoundException: The entity type 'RentABike.Models.Money' requires a key to be defined.
如果我声明一个密钥,则会为"Money"创建一个单独的表,这不是我想要的.
If I declare a key, a separate table for "Money" is created, which is not what I'm looking for.
是否可以在EF Core中使用ComplexType并将其全部放入单个表中?
Is there any way to use ComplexType in EF Core and put it all into a single table?
推荐答案
Support for complex types is currently on the backlog https://github.com/aspnet/EntityFramework/issues/246
这篇关于在Entity Framework Core中使用[ComplexType]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文