我真的用这个NHibernate查询敲我的头:)写一个连接。 我与资产和产品有许多关系。请找表格模型NHibernate查询加入多对多
public class Asset
{
string Id { get; set; }
List<Product> Products { get; set; }
}
public class Product
{
string Id { get; set; }
List<Asset> Assets { get; set; }
}
这里下面是我与QueryOver试图代码
Product productAlias = null;
Asset assetAlias = null;
var query = Session.QueryOver<Asset>(()=>assetAlias);
if (!string.IsNullOrEmpty(title))
query.WhereRestrictionOn(x => x.Title).IsLike(title, MatchMode.Anywhere);
if (!string.IsNullOrEmpty(productNumber))
{
query.WhereRestrictionOn(asset => asset.Products.First().Id).Equals(productNumber);
}
var result = query.List<Asset>();
谁能帮助如何写加入queryover所以,我要找到所有的标题是资产像标题和productnumber等于productnumber?
我没有得到上面的代码的结果。
The sql query i am trying to achieve is :
select a.* from Asset a ,
ManyToManyTable b on a.mat_id=b.mat_id
where a.title like '%test%' and b.prod_no='212300733'
感谢
我假设你实际上正在尝试'从Assess a * inner join * ManytoManyTable b on ...'中选择a。*。 –
不,我想要加入。资产可以有零个或多个产品。 –
如果它没有产品,它将永远不会与产品编号相匹配。 –