组件集合映射NHibernate 3.2
本文关键字:NHibernate 映射 集合 组件 | 更新日期: 2023-09-27 18:06:33
我有一个客户,它有地址:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Address> Addresses { get; private set; }
}
public class Address
{
public string City { get; set; }
public string Country { get; set; }
public string StreetName { get; set; }
public string ZipCode { get; set; }
}
我想把这个映射到NHibernate 3.2。它有流畅的接口,但与众所周知的fluent NHibernate不完全相同。我知道我必须使用Bag,或者Element?或组件?所以应该是这样的:
Bag(
property => property.Addresses,
collectionMapping => {}, // not important now
mapping => // and what should I use here, and how?
);
谢谢。
public class CustomerMap : ClassMapping<Customer>
{
public CustomerMap()
{
Id(x => x.ID, map => map.Generator(Generators.HighLow,
gmap => gmap.Params(new {max_low = 100})));
Property(x => x.Name,
map => { map.Length(150); map.NotNullable(true); });
Bag(x => x.Addresses,
collectionMapping =>
{
collectionMapping.Table("CustomerAddresses");
collectionMapping.Cascade(Cascade.All);
collectionMapping.Key(k => k.Column("CustomerId"));
});
}
}
更多信息:http://moh-abed.com/2011/08/14/nhibernate-3-2-mapping-entities-and-value-objects-by-code/