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,%'
组> 1-n> User2Group< n-1<用户 m-n关系
活动> 1-n>组 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);
我绊倒的是“on g.Id != ug.GroupID”
答案 0 :(得分:1)
当我看不到实体和映射时,有点困难,但是
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以来已经有一段时间了: - )