使用连接和where子句将查询转换为lambda表达式
本文关键字:转换 查询 lambda 表达式 子句 连接 where | 更新日期: 2023-09-27 18:06:38
我有这个查询,我有问题转换成lambda表达式
SELECT [dbo].[Prospects].[Id]
,[UserId]
,[NewId]
,[dbo].[Prospects].[Status]
FROM [dbo].[Prospects] join [dbo].[User] on [dbo].[User].Id = [dbo]. [Prospects].UserId
where [dbo].[Prospects].NewId = 3 and [dbo].[User].IsActive = 1
这是我得到的,但它不工作
var result = Workspace.Prospects.Join
(Workspace.Users, pros => pros.UserId,
use => use.Id, (pros, use)
=> new { Prospect = pros, User = use}).Where
(both => both.User.IsActive == true && both.Prospect.NewId == idVacante)
.OrderBy(both => both.Prospect.Id).AsEnumerable().ToList();
List<Prospect> prospects = result.Cast<Prospect>().ToList();
这并不难。您可以在连接表之前过滤它们
var result = Workspace.Prospects.Where(x=> x.NewId == 3)
.Join(Workspace.Users.Where(x => x.IsActive == 1),
p => p.UserId,
u => u.Id,
(p, u) => new { p.Id, p.UserId, p.NewId, p.Status })