Many to Many bidirectional with fluent NHibernate

12 views
Skip to first unread message

Christian I.

unread,
May 22, 2013, 1:32:18 AM5/22/13
to nhu...@googlegroups.com
Hello,

What I have to change in the mapping below to have a bidirectionnal relation ? I'd like when I have a "ProductDetail" object have access to "Product" at this time Product properties is always null when I get a ProductDetail.

Thanks,


public class ProductMap : ClassMap<Product>
{
public ProductMap()
{
Id(x => x.Id).GeneratedBy.Native();
Map(x => x.Code)
.Length(20)
.Unique()
.Not.Nullable();
Map(x => x.CreationDate).Not.Nullable();

HasManyToMany(x => x.Details)
.AsSet()
.Cascade
.SaveUpdate()
.Table("ProductsProductsDetails");
}
}

class ProductDetailMap : ClassMap<ProductDetailDb>
{
public ProductDetailMap()
{
Table("ProductDetail");
Id(x => x.Id).GeneratedBy.Native();
Map(x => x.Name)
.Length(150)
.Not.Nullable();
References(x => x.Language)
.Columns("LanguageId")
.Not.Nullable();
HasManyToMany(x => x.Products)
.AsSet()
.Inverse()
.Table("ProductsProductsDetails");
}
}
Reply all
Reply to author
Forward
0 new messages