views:

20

answers:

1

Is it possible to map the following situation?

  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.

A: 

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);
            }
        }
    }
Rafael Belliard
Thanks Rafael. Do you know whether it is possible to have the AccountProduct class inherit from Product and for the Account class to have a property to AccountProducts called Products? From the model perspective I'd ideally like to just expose Product and Account where Account has a property Products that links specifically to its products and includes the join table extra data (AccountProduct data). The join table doesn't really have a purpose on its own.
Sam