0

i have many ids of persons that i want see group is Assigned to this person، i have sql query like this

SELECT * 
FROM cor.[Group] AS g 
LEFT JOIN cor.PersonGroup AS pg ON 
g.Id=pg.GroupId  AND 
pg.PersonId IN (1,2)

and i want to give linq query for this i write this linq query

from g in _context.Groups join
                     pg in _context.PersonGroups.Where(pp =>personIds.Contains( pp.PersonId))
                    on g.Id equals pg.GroupId

But this is different from what I want

Mohammad hossein
  • 255
  • 3
  • 8
  • 17

1 Answers1

2

Try the following:

var persons = from grp in _context.Groups
              join pg in _context.PersonGroups on grp.Id equals pg.GroupId
              where personIds.Contains(pg.PersonId)
              select pg;
Sean Sailer
  • 343
  • 1
  • 12