需要明确的是,我希望将一个完整的对象及其所有属性映射到基本同一张表的不同副本。我的搜索向我展示了如何在多个表中拆分对象的属性,但这不是我想要完成的。
这是我的对象模型(精简):
class Customer
{
public Guid CustomerGuid { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
class Address
{
public Guid AddressGuid { get; set; }
public string Line1 { get; set; }
public string State { get; set; }
}
class Application
{
public Guid ApplicationGuid { get; set; }
public Address Address { get; set; }
public DateTime SubmittedDate { get; set; }
}
问题是我需要地址像一个组件一样排序,但要保存到两个单独的表中:CustomerAddress 和 ApplicationAddress,如下所示:
table Customer
(
CustomerGuid
Name
)
table Application
(
ApplicationGuid
SubmittedDate
)
table CustomerAddress
(
CustomerGuid
Line1
State
)
table ApplicationAddress
(
ApplicationGuid
Line1
State
)
我知道我可以使用一对一 (HasOne) 来完成其中一个映射,比如 Customer 到 CustomerAddress,但是我怎样才能对 Application 到 ApplicationAddress 做同样的事情呢?