Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将以下SQL转换为Linq?_C#_Linq_Linq To Sql_Iqueryable - Fatal编程技术网

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'