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

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

问题描述

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



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

 公共类实体{
public string StringProp {get; set;}
public SubEntity NestedEntity {get; set;}
}

其中SubEntity为:

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

如何将其映射到具有StringProp列的表和IntProp。基本上,表中的一条记录是由Entity和SubEntity的属性组成的。



我试图忽略SubEntity并在Entity中公开它的属性,但这是行不通的因为忽略NestedEntity时,使用其属性的Entity上的任何属性都没有值。



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

映射到所有必需的表列。
它可以很好地解决。
将在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;}
}

where SubEntity is :

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

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.

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?

解决方案

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天全站免登陆