0

与此 SQL 查询具有相同结果的 NHibernate 过滤器是什么:

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)    
4

1 回答 1

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")));
于 2013-07-10T13:51:55.853 回答