【问题标题】:Map column to child object in EF Core 3将列映射到 EF Core 3 中的子对象
【发布时间】:2020-05-07 11:19:31
【问题描述】:

给出下面的示例,有没有办法在不使用表拆分或拥有类型(例如 EF6 复杂类型)的情况下将 Address 与 User 放在同一个表中?生成的 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; }
    }

我看到的唯一其他选项是将 Address 映射到它自己的表。

【问题讨论】:

标签: c# sql-server entity-framework-core ef-core-3.1


【解决方案1】:

我将使用 1 到 0..1 的关系或直接在 User 中包含属性。

尽管如此,使用 Owned Types 作为 EF 6 中的 ComplexTypes 的替代品是可怕的,如果从 SQL 的角度来看不是完全没用的话,而且我看不出任何连接的原因。也许有人可以澄清完整性的适当理由

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-31
    • 2017-03-06
    • 1970-01-01
    相关资源
    最近更新 更多