c# - 将列映射到 EF Core 3 中的子对象
问题描述
给出下面的示例,有没有办法在不使用表拆分或拥有类型(例如 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; }
}
我看到的唯一其他选择是将地址映射到它自己的表。
解决方案
我将使用 1 到 0..1 的关系或直接在 User 中包含属性。
尽管如此,使用 Owned Types 作为 EF 6 中的 ComplexTypes 的替代品是可怕的,如果从 SQL 的角度来看不是完全没用的话,而且我看不出有任何加入的原因。也许有人可以澄清完整性的适当理由
推荐阅读
- amazon-web-services - 错误管道步骤“无服务器部署”显示“IamRoleLambdaExecution - 角色 XXXXX 的最大策略大小超过 10240 字节”
- bash - 如果第一列中的值匹配并且第二列中的值与bash中另一个文件中的值不匹配,则提取行
- oracle - 我无法删除 sqlplus 中的所有表
- c# - 匹配字符串中的两个正则表达式
- wordpress - 向 Wordpress 添加大型复杂自定义页面?
- r - 如何在用“vcd”制作的关联图中格式化 p 值?
- qt - 在 Qt 中编写自定义按钮的好方法是什么?
- windows - 等待由 IContextMenu.InvokeCommand 启动的进程
- apache-camel - 如何使用骆驼邮件将带有内联附件的电子邮件发送到 Outlook
- c# - 如何获得调整后图像的大小?