I have a db schema along the lines of:
<<>Product>
- ID
- ProductName
- Description
- StoreBrand
<><>ProductVariation>
- VariationID
- ProductID
- Size
- StoreBrand
- Price
可以预测,这些等级就象这样:
public class Product
{
public virtual int ID { get; set; }
public virtual string ProductName { get; set; }
public virtual string Description { get; set; }
public virtual string StoreBrand { get; set; }
public virtual IEnumerable<ProductVariation> Variations { get; set; }
}
public class ProductVariation
{
public virtual int VariationID { get; set; }
public virtual int ProductID { get; set; }
public virtual Product Product {get; set;}
public virtual string Size { get; set; }
public virtual double Price { get; set; }
}
下面是图象:
public class ProductMapper : ClassMap<Product>
{
public ProductMapper()
{
Id(x => x.ID);
Map(x => x.ProductName);
Map(x => x.Description);
Map(x => x.StoreBrand);
HasMany(x => x.Variations)
.KeyColumn("ProductID");
}
}
public class ProductVariationMapper : ClassMap<ProductVariation>
{
public ProductVariation()
{
Id(x => x.ID);
Map(x => x.ProductID);
Map(x => x.Size);
Map(x => x.Price);
References(x => x.Product)
.Column("ProductID");
}
}
页: 1
然而,我需要做的是将产品捆绑在一起。 Brands与产品Variation。 Brands 以及...(和反之亦然)
So querying Product, returns a list of it s ProductVariations for that brand... (Notice, ProductVariation doesn t have a property in the class, but it has the column for mapping)
ProductVariation.ID is non unique. The key is ProductVariation.ID and ProductVariation.Brand (on the database)