【发布时间】:2019-12-03 00:13:15
【问题描述】:
我在 SQL 中有一个查询需要转换为 lambda 表达式,但我不确定如何使用 WHERE 函数。
这是我在 SQL 中的查询:
SELECT * FROM 门票 t t.GroupId = g.GroupId 上的 INNER JOIN 组 g 其中 g.UserId = 4 AND t.StatusId = 3 或 t.UserCreatedBy = 4 AND t.StatusId = 3
我尝试通过以下方式对其进行转换:
var query = db.Tickets
.Include(t => t.CftGroup)
.Include(t => t.Customer)
.Include(t => t.Factory)
.Include(t => t.Failure)
.Include(t => t.Line)
.Include(t => t.Priority)
.Include(t => t.Process.ProcessGroup)
.Include(t => t.Site)
.Include(t => t.Status)
.Join(db.Groups, t => t.CftGroupId, g => g.CftGroupId, (t, g) => new
{
userCreatedBy = t.UserCreatedBy,
userId = g.UserId,
statusId = t.StatusId
})
.Where(
x => x.userId == id
&& x.statusId != Closed
|| x.userCreatedBy = id
&& x.statusId != Closed
);
【问题讨论】:
-
where子句有什么问题? -
你试过了,太棒了!但结果如何?
-
也许我的SQL to LINQ Recipe 可以帮助你。
-
为什么你的LINQ有
x.statusID != Closed而你的SQL有t.StatusId = 3?