NHibernate / Fluent NHibernate Mapping
Is it possible to map the following s开发者_运维问答ituation?
- A product class (currently a table)
- An account class (currently a table)
- An accountproduct class (currently a join table but with additional information related to a specific product and account)
What I'd ideally like is accountproduct to extend product and to be available from account as a property Products.
The product class would exist seperately and provide it's own peristance.
How about the following:
public class AccountProduct
{
public virtual int Id { get; set; }
public virtual DateTime Date { get; set; }
public virtual string Comments { get; set; }
public virtual Account Account { get; set; }
public virtual Product Product { get; set; }
public class AccountProductMap : ClassMap<AccountProduct>
{
public AccountProductMap()
{
Id(x => x.Id);
Map(x => x.Date);
Map(x => x.Comments);
References(x => x.Account);
References(x => x.Product);
}
}
}
public class Product
{
public virtual int Id { get; set; }
public virtual int Name { get; set; }
public class ProductMap : ClassMap<Product>
{
public ProductMap()
{
Id(x => x.Id);
Map(x => x.Name);
}
}
}
public class Account
{
public virtual int Id { get; set; }
public virtual int Name { get; set; }
public class AccountMap : ClassMap<Account>
{
public AccountMap()
{
Id(x => x.Id);
Map(x => x.Name);
}
}
}
精彩评论