[Solved] How to write a Linq to entity statement, using sql not in operator [duplicate]


You can write something like that:

 var query = myEntities.Groupeusers
     .Where(gu => !myEntities.Utilisateur.Any(ut => ut.idgroupe == gu.idgroupe)).ToList();

That should work.

EDIT:

Try that query instead:

 var query = myEntities.Groupeusers
     .Where(gu => !myEntities.Utilisateur
                .SelectMany(ut=>ut.Groupeuser)
                .Any(gu => gu.Idgroupe == gu.Idgroupe)).ToList();

OR maybe even better:

 var query = myEntities.GroupeUsers
     .Except(myEntities.Utilisateur.SelectMany(ut => ut.Groupeuser))
     .ToList();

EDIT2:

If I understand your query correct, you would like to identify a special user entity.

var query = myEntities.GroupeUsers 
     .Except(myEntities.Utilisateur.Where(u => u.IdUser == id).SelectMany(ut => ut.Groupeuser)) 
     .ToList(); 

4

solved How to write a Linq to entity statement, using sql not in operator [duplicate]