简体   繁体   English

将列映射到 EF Core 3 中的子对象

[英]Map column to child object in EF Core 3

Giving the sample below, is there any way to have Address in the same table as User without making use of table splitting or owned types (eg like EF6 complex types)?给出下面的示例,是否有任何方法可以在不使用表拆分或拥有的类型(例如 EF6 复杂类型)的情况下将 Address 与 User 放在同一个表中? The generated SQL prevents me from using it and complex types does not seem to be supported in EF Core 3:生成的 SQL 阻止我使用它,EF Core 3 似乎不支持复杂类型:

    public class User
    {
        public int Id { get; set; }

        public Address Address { get; set; }

        public string UserName { get; set; }
    }


    public class Address
    {
        public string StreetAddress { get; set; }

        public string City { get; set; }

        public string State { get; set; }

        public string ZipCode { get; set; }
    }

The only other options I see would be to map Address to its own table.我看到的唯一其他选项是将 Address 映射到它自己的表。

I will use a 1 to 0..1 relationship or include the properties in User directly.我将使用 1 到 0..1 的关系或直接在 User 中包含属性。

Nevertheless, using Owned Types as a replacement for ComplexTypes like in EF 6 is horrible , if not completely useless from a SQL perspective, and I cannot see any reason for the joins.尽管如此,像 EF 6 一样使用拥有的类型作为 ComplexTypes 的替代品是可怕的,如果从 SQL 的角度来看不是完全没用的话,我看不出任何连接的原因。 Maybe someone can clarify a proper justification for completness也许有人可以澄清完整性的适当理由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM