加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core-mvc – 在Entity Framework Core中使用[ComplexTyp

发布时间:2020-12-16 00:06:20 所属栏目:asp.Net 来源:网络整理
导读:我在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;
我在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并将它们全部放入一个表中?

解决方法

目前,https://github.com/aspnet/EntityFramework/issues/246的积压支持复杂类型

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读