我正在使用标准来计算行数。 考虑一个班级
class GroupMembership{
public Group Group{get;set;}
public Member Member{get;set;}
}
我有一个标准,为每个组提取不同的成员:
DetachedCriteria.For<GroupMembership>("this")
.CreateCriteria("Group", "grp")
.CreateAlias("this.CommunityMember", "CommunityMember")
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("this.Group.Id"),"GroupId")
.Add(Projections.CountDistinct("this.CommunityMember.Id"), "TotalMembers"))
如果没有与社区成员进行内部联接,我有没有办法计算。
更新: 我正在添加从查询生成的SQL
SELECT this_.GroupId as y0_,
count(distinct communitym2_.CommunityMemberId) as y1_
FROM [GroupMembership] this_
inner join [CommunityMember] communitym2_
on this_.CommunityMemberId = communitym2_.CommunityMemberId
inner join [Group] grp1_
on this_.GroupId = grp1_.GroupId
GROUP BY this_.GroupId
正如您所看到的,我们可以轻松避免SQL中的内部联接。我的问题是,是否可以在标准中做同样的事情。
答案 0 :(得分:1)
怎么样......
DetachedCriteria.For<GroupMembership>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("Group"))
.Add(Projections.CountDistinct("CommunityMember")))