LINQ 中有 3 个 where 子句

发布于 2024-12-27 15:44:20 字数 1088 浏览 3 评论 0原文

我在 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, ...});

,我也尝试过有 2 个连接 -

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

我在这里做错了什么?

问候, 巴维克

I have 3 where clauses in LINQ, but its failing - I tried this

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, ...});

I also tried to have 2 joins -

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

What am i doing wrong here?

Regards,
Bhavik

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘过的浮云 2025-01-03 15:44:20

试试这个。我用“and”更改了“where”

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, ...});

,您需要指定公司和角色的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,..});

Try this. I changed the "where" with an "and"

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, ...});

And you need to specify the id of the companies and roles:

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,..});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文