0
我是新来的流利NHibernate。C#流利的NHibernate查询如何查询来自Link表中的记录在很多关系中
我有以下对于多对多关系的映射。
如何使用queryover编写查询,以便在产品表中不存在但产品链表中可用的产品时带回记录?由于某些原因,数据不合适,因为它是遗留系统。所以不希望忽略不是产品表的记录。
任何人都可以请帮我怎么做到这一点?
Product productAlias = null;
Asset assetAlias = null;
var query = Session.QueryOver(() => assetAlias);
//Condn1: must be linked to a Product number
query.Inner.JoinAlias(() => assetAlias.Products,() => productAlias);
var result = query
.Skip(pageIndex * pageSize)
.Take(pageSize)
.Future<Asset>();
资产
public AssetMap()
{
Table("ASSET_INFO");
Id(x => x.Id).GeneratedBy.Assigned().Column("MAT_ID");
Map(x => x.Title);
HasManyToMany(x => x.Products)
.Table("PROD_LINK")
.AsBag()
.ParentKeyColumn("MAT_ID")
.ChildKeyColumn("PROD_NO")
.Cascade.All()
.LazyLoad();
}
产品
public ProductMap()
{
Table("PROD_INFO");
Id(x => x.Id).GeneratedBy.Assigned().Column("PROD_NO");
Map(x => x.Name).Column("PROD_NM");
HasManyToMany(x => x.Assets)
.Table("PROD_LINK")
.ParentKeyColumn("PROD_NO")
.ChildKeyColumn("MAT_ID")
.Inverse()
.LazyLoad();
}
PRODUCTLINK
public class ProductLinkMatMap : ClassMap<ProductLinkMat>
{
public ProductLinkMatMap()
{
Table("PROD_LINK");
CompositeId().KeyReference(x => x.Asset, "MAT_ID")
.KeyReference(x => x.Product, "PROD_NO");
}
}