有没有办法用 EF Core 映射复杂类型 [英] Is there a way to map complex types with EF Core

查看:47
本文介绍了有没有办法用 EF Core 映射复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EF Core 不支持复杂类型映射.

EF Core does not support Complex types mapping.

如果我有一个对象,例如:

If I had an object such as:

public class Entity { 
    public string StringProp {get; set;}
    public SubEntity NestedEntity {get; set;}
}

子实体在哪里:

public class SubEntity{
    public int IntProp {get; set;}
}

如何将其映射到包含 StringProp 和 IntProp 列的表.基本上表中的一条记录由Entity和SubEntity的属性组成.

How could I map this to a table that has columns for StringProp and IntProp. Basically one record in the table is composed of the properties of both Entity and SubEntity.

我尝试忽略 SubEntity 并在 Entity 中公开它的属性,但这不起作用,因为当 NestedEntity 被忽略时,Entity 上使用其属性的任何属性都没有值.

I've tried ignoring SubEntity and exposing it's properties in Entity but that doesn't work because when NestedEntity is ignored any properties on Entity using its properties have no values.

除了创建具有复杂类型所有属性的类或重构数据库之外,还有其他选择吗?

Is there any other option than creating a class that has all the properties of the complex type or refactoring the database?

推荐答案

我决定使用一个包含所有相关属性和映射到所有必需的表列.它作为一种解决方法工作正常.当 EF Core 支持复杂类型时会更新.

I have decided to go with a class that contains all the relevant properties and maps to all the required table columns. It works fine as a workaround. Will update when there is support for complex types in EF Core.

这篇关于有没有办法用 EF Core 映射复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆