要清楚,我希望将一个整个对象及其所有属性映射到基本上同一表的不同副本。我的搜索向我展示了如何将对象的属性划分为多个表,但这不是我要完成的。
这是我的对象模型(剥离):
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)来完成对客户的映射之一,但是我该如何在应用程序上使用应用程序?
适用于客户的类似物
class CustomerMap : ClassMap<Customer>
{
public CustomerMap()
{
Id(x => x.Id, "CustomerGuid").GeneratedBy.GuidComb();
Map(x => x.Name);
Join("CustomerAddress", join =>
{
join.KeyColumn("CustomerGuid");
join.Component(x => x.Address, c =>
{
c.Map(x => x.Line1);
c.Map(x => x.State);
});
});
}
}