C# 将Sql转换为Linq
如何翻译C# 将Sql转换为Linq,c#,linq,C#,Linq,如何翻译 select *from ( select EmployeeID,FirstName,LastName,Region from Employees where city in ('London','Seattle') ) x where x.Region is not null 转化为Linq等价物 我尝试过(但也选择了空值) Threadpool,您需要看一看名为Linqer的产品(我与它没有关联)。太棒了。它将SQL查询转换为LINQ。我还
select *from
(
select EmployeeID,FirstName,LastName,Region from Employees where city
in ('London','Seattle')
)
x
where x.Region is not null
转化为Linq等价物
我尝试过(但也选择了空值)
Threadpool,您需要看一看名为Linqer的产品(我与它没有关联)。太棒了。它将SQL查询转换为LINQ。我还没有遇到它无法处理的查询。Threadpool,您需要看看名为Linqer的产品(我与它没有关联)。太棒了。它将SQL查询转换为LINQ。我还没有遇到一个它无法处理的查询。这是你的括号。在你所在城市的城市或声明中,你会错过它们。
LinqDBDataContext Context = new LinqDBDataContext();
var query = from emps in
(
from empls in Context.Employees
where (empls.City == "London" || empls.City == "Seattle")
&& empls.Region != null
select new
{
FirstName = empls.FirstName,
LastName = empls.LastName,
City = empls.City,
Region = empls.Region
}
)
select emps;
GridView1.DataSource = query;
GridView1.DataBind();
这是你的括号。在你所在城市的城市或声明中,你会错过它们。
LinqDBDataContext Context = new LinqDBDataContext();
var query = from emps in
(
from empls in Context.Employees
where (empls.City == "London" || empls.City == "Seattle")
&& empls.Region != null
select new
{
FirstName = empls.FirstName,
LastName = empls.LastName,
City = empls.City,
Region = empls.Region
}
)
select emps;
GridView1.DataSource = query;
GridView1.DataBind();
您的sql可以重新写入为:
select EmployeeID,FirstName,LastName,Region
from Employees
where city in ('London','Seattle')
and Region is not null
您的sql可以重新写入为:
select EmployeeID,FirstName,LastName,Region
from Employees
where city in ('London','Seattle')
and Region is not null
您需要将where子句更改为: 其中(就业城市==“伦敦”|就业城市==“西雅图”)&就业地区!=空的
如果没有parens,您将在London上获得空值您需要将where子句更改为: 其中(就业城市==“伦敦”|就业城市==“西雅图”)&就业地区!=空的
如果没有这些参数,您在伦敦的查询结果将为空。您的查询是否可以简化为:从员工中选择EmployeeID、FirstName、LastName、Region,其中city in('London'、'Seattle')和Region都不是空的?是的,可能是空的。我将更正它。我刚刚通过Linqer运行了您的查询。下面是它得出的结论:来自t in Employees where(新字符串[]{“London”,“settle”})。包含(t.City)和&t.Region!=空选择新{t.EmployeeID,t.FirstName,t.LastName,t.Region}@Randy Minder哦!谢谢,我会选择试用版。你的查询不能简化如下:从雇员中选择EmployeeID、FirstName、LastName、Region,其中city在('London'、'Seattle'),Region不是空的。是的,可以。我会更正它。我刚刚通过Linqer运行了你的查询。下面是它得出的结论:来自t in Employees where(新字符串[]{“London”,“settle”})。包含(t.City)和&t.Region!=空选择新{t.EmployeeID,t.FirstName,t.LastName,t.Region}@Randy Minder哦!谢谢,我会去试用版的。