C# 在LINQ中有3个where子句

C# 在LINQ中有3个where子句,c#,linq,entity-framework-4,linq-to-entities,C#,Linq,Entity Framework 4,Linq To Entities,我在LINQ中有3个where子句,但它失败了——我尝试了这个 List<string> companies = new List<string>() { "0001001429"}; List<string> roleIDs = new List<string>() { "1486334", "1419282"}; var q = (from up in UserReports where up.UserType == "In

我在LINQ中有3个where子句,但它失败了——我尝试了这个

List<string> companies = new List<string>() { "0001001429"};
List<string> roleIDs = new List<string>() { "1486334", "1419282"};


var q = (from up in UserReports
        where up.UserType == "Internal"     
        where companies.Contains(up.CompanyId) && roleIDs.Contains(up.RoleId)
                             select new 
                             {
                                 UserId = up.UserId,
                                 FirstName = up.FirstName,
                                 LastName = up.LastName, ...});
我做错了什么

问候,, 巴维克试试这个。我把“where”改成了“and”

您需要指定公司和角色的id:

var q = (from up in UserReports
                         join c in companies on up.CompanyID equals c.Id
                         join r in rolesIDs on up.RoleId equals r.Id
                         where up.UserType == "Internal"
                         select new 
                         {
                             UserId = up.UserId,..});

弱点。。。你能不能精确一点,那部分失败了,因为它既没有编译也没有给出结果。对于第一个答案,我得到了以下错误-委托“System.Func”不接受我在问题中两次错误复制的1个参数:)让我试试第二个解决方案。上面哪一个更好?就性能而言,第一个将被编译为
in
sql子句中的
,我想它将是最好的。
var q = (from up in UserReports
    where up.UserType == "Internal"     
    && companies.Contains(up.CompanyId) && roleIDs.Contains(up.RoleId)
                         select new 
                         {
                             UserId = up.UserId,
                             FirstName = up.FirstName,
                             LastName = up.LastName, ...});
var q = (from up in UserReports
                         join c in companies on up.CompanyID equals c.Id
                         join r in rolesIDs on up.RoleId equals r.Id
                         where up.UserType == "Internal"
                         select new 
                         {
                             UserId = up.UserId,..});