Если вы ищете полный учебник о том, как это сделать, я рекомендую FNH wiki или одно из многих сообщений в блогах, которые можно найти через Google.
Однако вы пытаетесь реализовать отношения «многие ко многим» здесь, и это, похоже, отбрасывает много людей. Вот грубый гид:
В классе клиента, вы будете нуждаться в коллекции, как:
IList<Product> Products { get; private set; }
И точно так же, на классе продукта:
IList<Customers> Customers { get; private set; }
Вы начинаете с МНОГИХ ко-многим карта с функцией HasManyToMany
:
public class CustomerMap : ClassMap<Customer>
{
public CustomerMap()
{
// other mappings
HasManyToMany<Product>(x => x.Products)
.WithTableName("Cust_Product") // Specifies the join table name
.WithParentKeyColumn("CustomerId") // Specifies the key joining back to this table (defaults to [class]_id, Customer_id in this case)
.WithChildKeyColumn("ProductId")
.FetchType.Join(); // Instructs NHibernate to use a join instead of sequential select
}
}
Затем повторите процедуру для другого (свойство Customers в классе Product).
большое спасибо Стюарт ... –