如何在LINQ中执行以下查询?

时间:2019-07-10 05:51:54

标签: sql linq

我在LINQ中需要执行一个SQL查询。有人可以帮忙转换吗?

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

1 个答案:

答案 0 :(得分:1)

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