开发者

component collection mapping NHibernate 3.2

开发者 https://www.devze.com 2023-03-30 22:18 出处:网络
I have a Customer which has Addresses: public class Customer { public int Id { get; set; } public string Name { get; set; }

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 st开发者_如何学Goring 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/

0

精彩评论

暂无评论...
验证码 换一张
取 消