在 Entity Framework Core 中使用 [ComplexType]

编程入门 行业动态 更新时间:2024-10-28 20:25:03
本文介绍了在 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?

推荐答案

对复杂类型的支持目前处于积压状态 github/aspnet/EntityFramework/issues/246

Support for complex types is currently on the backlog github/aspnet/EntityFramework/issues/246

更多推荐

在 Entity Framework Core 中使用 [ComplexType]

本文发布于:2023-10-16 00:49:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Framework   Entity   ComplexType   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!