Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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/0/asp.net-mvc/14.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# 如何在MVC中实现SQL语句到LINQ?_C#_Asp.net Mvc_Asp.net Mvc 4_Model View Controller_Visual Studio 2012 - Fatal编程技术网

C# 如何在MVC中实现SQL语句到LINQ?

C# 如何在MVC中实现SQL语句到LINQ?,c#,asp.net-mvc,asp.net-mvc-4,model-view-controller,visual-studio-2012,C#,Asp.net Mvc,Asp.net Mvc 4,Model View Controller,Visual Studio 2012,你好 我需要将以下SQL解释为LINQ select t1.req_no, t1.seq_no, t1.quantity, t1.uom, t1.item_name, t2.event_date from tb_cs_test t1, tb_cs_test2 t2 where (t1.req_no = 1 and t2.req_no = 1 ); 我使用MVC,在这个SQL语句中,我需要根据我输入的条件抛出请求的字段

你好

我需要将以下SQL解释为LINQ

select 
      t1.req_no,
      t1.seq_no,
      t1.quantity,
      t1.uom,
      t1.item_name,
      t2.event_date 
from tb_cs_test t1, tb_cs_test2 t2 where (t1.req_no = 1 and t2.req_no = 1 );
我使用MVC,在这个SQL语句中,我需要根据我输入的条件抛出请求的字段


谢谢

您可以通过
加入

from t1 in tb_cs_test 
join t2 in tb_cs_test2 
on t1.req_no equals t2.req_no
where t1.req_no = 1
select new {
  t1.req_no,
  t1.seq_no,
  t1.quantity,
  t1.uom,
  t1.item_name,
  t2.event_date 
}
你可以这样写

            var dfg = from t1 in tb_cs_test t1
                      from t2 in tb_cs_test2 t2
                      where t1.req_no == 1 && t2.req_no == 1
                      select new
                      {
                          t1.req_no,
                          t1.seq_no,
                          t1.quantity,
                          t1.uom,
                          t1.item_name,
                          t2.event_date

                      };

我已经试过我这边的语法了

到目前为止你试过了什么?你的班级结构是什么?这已经是Linq。。。你能再解释一下,给我们一些背景吗?您是从哪里获得此代码段的,需要做什么。@Glubus发布的代码是SQL,而不是Linq。问题:为什么需要将其重构为Linq?有很好的工具可以使用现有的、完全工作的、参数化的SQL并高效、方便地运行它们,而无需支付与LINQ相关的表达式树构建、检查和查询生成的开销;例如,您是否可以在这里使用Dapper,然后它就是
var data=connection.Query(@“your sql here”,new{/*named args here,作为对象初始值设定项*/)对不起,我输入的代码是在PLSQL中使用的,所以我需要做同样的事情,但对于MVC,这很好!谢谢