我有一组通过引用表(产品、商店和商店产品)映射的表
表
Table: Product
---------------
Name
Id
Desc
Table: Stores
---------------
Name
Id
ZipCode
Table: StoreProduct
---------------
Id
StoreId
ProductId
isAvailable
ShelfID
楷模
public class Store
{
public int Id {get;set;}
public string Name {get;set;}
public List<Product> Products {get;set;}
}
public class Product
{
public int Id {get;set;}
public string Name {get;set;}
public bool isAvailable {get;set;}
public int ShelfId {get;set}
public List<Store> Stores {get;set;}
}
映射
public class StoreMap: ClassMap<Store>
{
public StoreMap()
{
Id(x => x.Id);
Map(x => x.Name).Length(255).Nullable();
HasMany(x => x.Products)
.Table("StoreProduct")
.ParentKeyColumn("StoreId")
.ChildKeyColumn("ProductId");
}
}
public class ProductMap: ClassMap<Product>
{
public ProductMap()
{
Id(x => x.Id);
Map(x => x.Name).Length(255).Nullable();
HasMany(x => x.Stores)
.Table("StoreProduct")
.ParentKeyColumn("ProductId")
.ChildKeyColumn("StoreId");
}
}
我查看了FluentNHibernate 查找表,但看不到如何将其应用于我的结构。我走的是正确的路线吗?如何使用 Fluent 映射将 StoreProduct 表映射到每个域模型?
其次,如何将参考查找表中的列映射到子表(参见 isAvailable 列)。