什么是NHibernate过滤器与此SQL查询具有相同的结果:
SELECT A.Id as ItemId, A.column1 as ItemTitle, A.ListId as ItemListId,
B.Id as LookupItemId, B.Value as LookupItemValue, B.ListId as LookupItemListId
FROM MyTable A LEFT JOIN MyTable B ON B.Id = A.LookupId
WHERE A.ListId = 'EmployeeListGuid'
AND (B.ListId='EmployeerListGuid' OR B.Id IS NULL)
答案 0 :(得分:0)
首先,为实体属性创建别名,这将LEFT JOIN
我们的表自我:
criteria.CreateAlias("LookupItem", "B", JoinType.LeftOuterJoin);
然后,我们可以在条件中使用此别名:
critera.Add(Restrictions.Eq("ListId", "EmployeeListGuid"));
critera.Add(
Restrictions
.Or(
Restrictions.Eq("B.ListId", "EmployeerListGuid"),
Restrictions.IsNull("B.Id")));