C# FluentNHibernate中的参考表
我有一组通过参考表(Products、Stores和StoreProducts)映射的表 表格C# FluentNHibernate中的参考表,c#,nhibernate,fluent-nhibernate,C#,Nhibernate,Fluent Nhibernate,我有一组通过参考表(Products、Stores和StoreProducts)映射的表 表格 Table: Product --------------- Name Id Desc Table: Stores --------------- Name Id ZipCode Table: StoreProduct --------------- Id StoreId ProductId isAvailable ShelfID public class Store { public
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");
}
}
型号
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");
}
}
公共类存储
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共列表产品{get;set;}
}
公共类产品
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共布尔值可用{get;set;}
公共int ShelfId{get;set}
公共列表存储{get;set;}
}
映射
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");
}
}
公共类存储映射:类映射
{
公共存储地图()
{
Id(x=>x.Id);
Map(x=>x.Name).Length(255).Nullable();
有很多(x=>x.Products)
.表格(“存储产品”)
.ParentKeyColumn(“存储ID”)
.ChildKeyColumn(“产品ID”);
}
}
公共类ProductMap:ClassMap
{
公共产品地图()
{
Id(x=>x.Id);
Map(x=>x.Name).Length(255).Nullable();
有很多(x=>x.Stores)
.表格(“存储产品”)
.ParentKeyColumn(“产品ID”)
.ChildKeyColumn(“存储ID”);
}
}
我已经看过了,但不知道如何将其应用到我的结构中。我走对路线了吗?如何使用Fluent映射将StoreProduct表映射到每个域模型
其次,我如何将一列从引用查找表映射到子表(请参见isAvailable列)。我认为这里有一个多对多关系。一个商店包含许多产品,一个产品可以由多个商店携带 像这样的
public ProductMap()
{
Id(x => x.Id);
Map(x => x.Name).Length(255).Nullable();
HasManyToMany(x => x.Stores)
.AsBag()
.Table("StoreProduct")
}
我认为你在这里有一种多对多的关系。一个商店包含许多产品,一个产品可以由多个商店携带 像这样的
public ProductMap()
{
Id(x => x.Id);
Map(x => x.Name).Length(255).Nullable();
HasManyToMany(x => x.Stores)
.AsBag()
.Table("StoreProduct")
}
谢谢,我会测试它,并根据需要更新问题/接受答案。谢谢,我会测试它,并根据需要更新问题/接受答案。