Skip to content
Advertisement

How to perform following query in LINQ?

I have a SQL query need to do in LINQ. Can anyone helps in converting?

SELECT * 
FROM profile 
WHERE ProfileId <> 1221 AND IsActive = 1 AND
      ProfileId NOT IN (SELECT ReportingPerson 
                        FROM ReportingPersons 
                        WHERE Employee = 1221)

Advertisement

Answer

     var reportingPerson = context.ReportingPersons.Where(x => 
                           x.Employee == 1221)
                           .Select(c => c.ReportingPerson
                           ).ToList();

     var result = context.Profiles
                         .Where(x => 
                                x.ProfileId != 1221 && 
                                x.IsActive && 
                                !reportingPerson.Contains(x.ProfileId)
                         .ToList();
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement