SELECT *
FROM [Group] g
INNER JOIN User2Group ug
    **on g.Id != ug.GroupId**
INNER JOIN [Activity] a
    on a.Id = g.ActivityId
WHERE g.UserId != 2
AND a.Lineage like '0,1,%'

组<!> gt; 1-n <!> gt; User2Group <!> lt; n-1 <!> lt;用户 m-n关系

活动<!> gt; 1-n <!> gt;组 1-N

尝试获取用户尚未添加到其帐户的所有群组。

到目前为止我所拥有的:

var groups = repository.SimpleQuery<Group>("from Group as g join fetch g.Users as u join fetch g.Activity as a where g.Type != ? and a.Lineage like ? and g.CreatedBy.Id != ?", Group.GroupType.Deleted, string.Format("{0}%", lineage), currentUser.Id);

我绊倒的是g .Id != ug.GroupID <!>

有帮助吗?

解决方案

当我看不到实体和映射时,有点困难,但是

on g.Id != ug.GroupId

部分可能用HQL表示

from Group as g where g.id not in (select u.group.id from User u where u.id = ?)

where子句的其余部分应该很容易添加。

请注意,自从我使用HQL以来已经有一段时间了: - )

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top