开发者

NHibernate / Fluent NHibernate Mapping

Is it possible to map the following s开发者_运维问答ituation?

  1. A product class (currently a table)
  2. An account class (currently a table)
  3. 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);
            }
        }
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜