Domanda

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,%'

Gruppo > 1-n & Gt; User2Group & Lt; n-1 < Utente relazione m-n

Attività > 1-n & Gt; Gruppo 1-n

Prova di ottenere tutti i gruppi che un utente non ha già aggiunto al proprio account.

Quello che ho finora:

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

Quello che mi ha fatto scattare è il " su g.Id ! = ug.GroupID "

È stato utile?

Soluzione

È un po 'difficile quando non vedo le entità e le mappature, ma

on g.Id != ug.GroupId

la parte potrebbe probabilmente essere espressa in HQL da

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

Il resto della clausola where dovrebbe essere facile da aggiungere.

Ricorda che è da un po 'che non lavoro con HQL :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top