C# 如何将以下SQL转换为Linq?
我正在使用C# 如何将以下SQL转换为Linq?,c#,linq,linq-to-sql,iqueryable,C#,Linq,Linq To Sql,Iqueryable,我正在使用IQueryable接口 如何将以下sql语句转换为IQueryable select * from customer where joindate > DateTime.Now and (customertype = 'system' or customerstatus = 'active') and customerlocation = 'europe' 我不记得linq是否会计算DateTime。现在,我只是提前将它放入一个变量中 我不记得linq
IQueryable
接口
如何将以下sql语句转换为IQueryable
select * from customer
where joindate > DateTime.Now and
(customertype = 'system' or customerstatus = 'active') and
customerlocation = 'europe'
我不记得linq是否会计算DateTime。现在,我只是提前将它放入一个变量中
我不记得linq是否会计算DateTime。现在,我只是提前将它放入一个变量中。类似这样的内容:
var result = from record in context.customer
where record.joindate > DateTime.Now &&
(record.customertype == "system" || record.customerstatus == "active") &&
record.customerlocation == "europe"
select record
有一个很好的工具Linqer,它可以帮助您将SQL查询转换为LINQ。当然,对于这种简单的情况,它是多余的,但是如果您更熟悉SQL.,当然可以考虑它的重查询。
您可以在这里找到它。类似这样的内容:
var result = from record in context.customer
where record.joindate > DateTime.Now &&
(record.customertype == "system" || record.customerstatus == "active") &&
record.customerlocation == "europe"
select record
有一个很好的工具Linqer,它可以帮助您将SQL查询转换为LINQ。当然,对于这种简单的情况,它是多余的,但是如果您更熟悉SQL.,当然可以考虑它的重查询。
您可以在这里找到它。我建议使用以下语法,但您也可以使用查询语法:
var results = yourContext.Customers.Where(c => (c.JoinDate > DateTime.Now) &&
((c.CustomerType.Equals("system") || (c.CustomerType.Equals("active")) &&
(c.CustomerLocation.Equals("europe")));
使用查询语法:
var results = from c in yourContext.Customers
where (c.JoinDate > DateTime.Now) &&
(c.CustomerType.Equals("system") || c.CustomerStatus.Equals("active")) &&
c.CustomerLocation.Equals("europe")
select c;
我提供了以下语法,但您也可以使用查询语法:
var results = yourContext.Customers.Where(c => (c.JoinDate > DateTime.Now) &&
((c.CustomerType.Equals("system") || (c.CustomerType.Equals("active")) &&
(c.CustomerLocation.Equals("europe")));
使用查询语法:
var results = from c in yourContext.Customers
where (c.JoinDate > DateTime.Now) &&
(c.CustomerType.Equals("system") || c.CustomerStatus.Equals("active")) &&
c.CustomerLocation.Equals("europe")
select c;
你不放customerlocation=='europe'你不放customerlocation=='europe'