组件集合映射NHibernate的3.2 [英] component collection mapping NHibernate 3.2
本文介绍了组件集合映射NHibernate的3.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个客户有地址:
公共类客户
{
公众诠释编号{获得;组; }
公共字符串名称{;组; }
公众的ICollection<地址>地址{获得;私定; }
}
公共类地址
{
公共字符串市{获得;组; }
公共字符串国家{获得;组; }
公共字符串StreetName {获得;组; }
公共字符串邮编code {获得;组; }
}
我想这个映射到NHibernate的3.2。它具有流畅的界面,但不完全一样知名的连贯NHibernate。 我知道,我必须用袋,也许元素?或组件? 因此,它应该是这样的:
袋(
属性=> property.Addresses,
collectionMapping => {} //重要的是现在没有
映射=> //我应该用什么在这里,怎么样?
);
感谢。
解决方案
公共类CustomerMap:ClassMapping<客户>
{
公共CustomerMap()
{
ID(X => x.ID,地图=> map.Generator(Generators.HighLow,
GMAP => gmap.Params(新{max_low = 100})));
物业(X => x.Name,
地图=> {map.Length(150); map.NotNullable(真正的); });
袋(X => x.Addresses,
collectionMapping =>
{
collectionMapping.Table(CustomerAddresses);
collectionMapping.Cascade(Cascade.All);
collectionMapping.Key(K => k.Column(客户ID));
});
}
}
更多信息:的http://moh-abed.com/2011/08/14/nhibernate-3-2-mapping-entities-and-value-objects-by-$c$c/
I have a Customer which has Addresses:
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; }
}
I want to map this to NHibernate 3.2. which has fluent interface, but not exactly the same as well-known Fluent NHibernate. I know that I have to use Bag, and maybe Element? Or component? So it should be something like this:
Bag(
property => property.Addresses,
collectionMapping => {}, // not important now
mapping => // and what should I use here, and how?
);
Thanks.
解决方案
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"));
});
}
}
more info: http://moh-abed.com/2011/08/14/nhibernate-3-2-mapping-entities-and-value-objects-by-code/
这篇关于组件集合映射NHibernate的3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文