我有两个数据库表:实体框架代码优先一比一的关系
客户
- 客户ID(PK)
- 名称
- ...
CustomerSettings
- 客户ID(PK)
- 设置1
- 设置2
- ...
是否有可能利用二维码的第一个拥有这些类?如果是这样,什么是流利的映射?
public class Customer
{
public int CustomerId { get; set; }
public int Name { get; set; }
public CustomerSetting CustomerSetting { get; set; }
}
public class CustomerSetting
{
public int CustomerId { get; set; }
public int Setting1 { get; set; }
public int Setting2 { get; set; }
public Customer Customer { get; set; }
}
我个人不喜欢一对一的表格。毕竟,为什么不把设置列添加到客户表?不幸的是,这是我需要开发的。我无法确定这种场景的正确的代码优先映射。谢谢你的帮助。
一种可能的情况。虽然这是不适合你的情况。我已经在我的答案中提出了解决方案。 –
听起来像别人正在口述数据模型。在这种情况下,首先选择模型或首先选择Db是比代码优先选择更好的选择。 – Maess