如何将此LINQ查询转换为使用Lambda表达式?

如何将此LINQ查询转换为使用Lambda表达式?,linq,linq-to-sql,Linq,Linq To Sql,我希望使用lambda表达式编写以下语法 from p in this.Context.tblUserInfos where p.Status == 1 select new {p.UserID,p.UserName,p.tblUserType.UserType }; 假设我写信 this.Context.tblUserInfos.Where(p => p.Status == 1); 如何使用=>运算符编写上述语法。使

我希望使用lambda表达式编写以下语法

  from p in this.Context.tblUserInfos
                where p.Status == 1
                select new {p.UserID,p.UserName,p.tblUserType.UserType };
假设我写信

this.Context.tblUserInfos.Where(p => p.Status == 1);

如何使用=>运算符编写上述语法。

使用
。选择
IEnumerable扩展方法将结果集投影到匿名类型

this.Context.tblUserInfos.Where(p => p.Status == 1)
            .Select(p => new { p.UserID, p.UserName, p.tblUserType.UserType });
像这样:

var someAnonymousType = this.Context.tblUserInfos
                             .Where(p => p.Status == 1)
                             .Select(p => new {p.UserID,p.UserName,p.tblUserType.UserType };);

使用
.Select
IEnumerable扩展方法将结果集投影到匿名类型中

像这样:

var someAnonymousType = this.Context.tblUserInfos
                             .Where(p => p.Status == 1)
                             .Select(p => new {p.UserID,p.UserName,p.tblUserType.UserType };);

您已经有了其中的where部分,所以我假设您只需要选择:

this.Context.tblUserInfos
            .Where(p => p.Status == 1)
            .Select(p => new { p.UserID, p.UserName, p.tblUserType.UserType });

您已经有了其中的where部分,所以我假设您只需要选择:

this.Context.tblUserInfos
            .Where(p => p.Status == 1)
            .Select(p => new { p.UserID, p.UserName, p.tblUserType.UserType });

可以在LINQ和lambda语法之间转换查询

可以在LINQ和lambda语法之间转换查询

出于好奇,为什么需要切换到lambda格式?因为它更古怪!出于好奇,为什么需要切换到lambda格式?因为它更古怪!