0

谁能建议如何将下面的 SQL 转换为 LINQ?

SELECT distinct EmployeeID
  FROM Employee,
       Business
 WHERE Administrator = 1 or 
         (BusinessID = 1 and
         (EmployeeID = Initiator or
          EmployeeID = Owner))

或者也许建议使用多个表达式实现相同结果的更好方法?我读过 LINQ 可能有问题,所以我认为查询越复杂,出现问题的可能性就越大?

4

1 回答 1

5

听起来您只想:

var query = (from employee in db.Employee
             from business in db.Business
             where employee.Administrator == 1 ||
                 (business.BusinessId == 1 &&
                  (employee.EmployeeId == business.Initiator ||
                   employee.EmployeeId == business.Owner))
             select employee.EmployeeId).Distinct();

我已经猜到哪一列属于哪个表...

于 2013-05-03T22:05:02.730 回答