Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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# 4.0 从sql语句到linq语句的转换_C# 4.0 - Fatal编程技术网

C# 4.0 从sql语句到linq语句的转换

C# 4.0 从sql语句到linq语句的转换,c#-4.0,C# 4.0,我怎么翻译 select * from employees where (emp_id=@emp or @emp is null) and (dep_id=@dep or @dep is null) 到LINQ Station?C# 我假设@emp为null部分是一个输入错误,并且您希望emp\u id为null。如果没有,就把它调换一下 我建议用LINQ。对不起,没有办法。LINQ提供程序的设计目的是获取代码并转换为SQL语句,而不是相反 int empID = [whatever...]

我怎么翻译

select * from employees where (emp_id=@emp or @emp is null) and (dep_id=@dep or @dep is null)
到LINQ Station?

C#

我假设
@emp为null
部分是一个输入错误,并且您希望
emp\u id为null
。如果没有,就把它调换一下


我建议用LINQ。

对不起,没有办法。LINQ提供程序的设计目的是获取代码并转换为SQL语句,而不是相反

int empID = [whatever...]

var e = from e in db.Employees
        where e.emp_id == empID || e.emp_id == null
        select e;