小编Jay*_*Jay的帖子

生成的SQL的差异

以下c#代码:

Func<Customer, bool> predicate1 = s => s.Name == "Roger";
dbContext.Customers.Where(predicate1);
Run Code Online (Sandbox Code Playgroud)

生成这个SQL查询:

select col1,col2 from customers 
Run Code Online (Sandbox Code Playgroud)

注意在上面的sql查询中,没有where子句.

但是,在这个c#代码中:

dbContext.Customers.Where(s => s.Name == "Roger");   
Run Code Online (Sandbox Code Playgroud)

它产生:

select col1,col2 from customers where name = 'Rogers'
Run Code Online (Sandbox Code Playgroud)

为什么有区别?有没有办法传递像上面这样的谓词,仍然生成带有where子句的SQL查询?

c# linq linq-to-entities linq-to-sql

2
推荐指数
1
解决办法
52
查看次数

标签 统计

c# ×1

linq ×1

linq-to-entities ×1

linq-to-sql ×1