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# 如何将此T-Sql转换为linq_C#_Linq - Fatal编程技术网

C# 如何将此T-Sql转换为linq

C# 如何将此T-Sql转换为linq,c#,linq,C#,Linq,我编写了这个tsql查询 ((SELECT Id,[Mesc] ,[Line] ,[Unit] ,[Discription] ,[InvQty] ,[LastDateNil] ,[StCode] ,[PlanCode] ,[MIN] ,[MAX] ,[LastDateConsum] ,[PbsNo] ,[PbsDate] ,[PbsQty]

我编写了这个tsql查询

((SELECT Id,[Mesc]
      ,[Line]
      ,[Unit]
      ,[Discription]
      ,[InvQty]
      ,[LastDateNil]
      ,[StCode]
      ,[PlanCode]
      ,[MIN]
      ,[MAX]
      ,[LastDateConsum]
      ,[PbsNo]
      ,[PbsDate]
      ,[PbsQty]
      ,[PbsQtyRec]
      ,[DateDelay]
      ,[TypeRequest]
      ,[HeaderId]
  FROM [MyMaterialDB].[dbo].[Report2]
  WHERE headerid IN(SELECT HeaderId FROM [MyMaterialDB].[dbo].[Report2] WHERE line='I'))

  Order by Mesc,Line,unit

我想把这个转换成linq,但我在linq是个大人物,请帮帮我。谢谢大家。

除非是打字错误,否则不需要内部选择:

SELECT [Id], [Mesc], <etc>
  FROM [MyMaterialDB].[dbo].[Report2]
  WHERE line='I'
  ORDER BY Mesc,Line,unit
选择[Id],[Mesc],
来自[MyMaterialDB].[dbo].[Report2]
我在哪里
按Mesc、生产线、单位订购
所以你的LINQ应该是这样的:

report2
  .Select(x => new { x.Id, x.Mesc, <etc> })
  .Where(x => x.line == "I")
  .OrderBy(x => x.Mesc)
  .ThenBy(x => x.Line)
  .ThenBy(x => x.unit)
report2
.Select(x=>new{x.Id,x.Mesc,})
.其中(x=>x.line==“I”)
.OrderBy(x=>x.Mesc)
.ThenBy(x=>x.Line)
.ThenBy(x=>x.unit)

(注意,我的头顶上有一个问题——可能需要稍微纠正一下)。

为什么不先学习就想切换到linq?至少是基础知识?你尝试过什么并且失败了(在“失败”一词中,我指的是你知道的所有意外行为。所以,如果你在问题结束之前更新了问题,让我们确切地知道问题是如何失败的)?斯图史密斯:谢谢你的帮助,但我的查询是从[MyMaterialDB].[dbo].[Report2]中选择[Id],[Mesc],从[MyMaterialDB]。[Report2]中选择headerid在哪里(headerid来自[Report2]行class='I')是的,我认为不需要内部选择:它是同一个表的联接(
Report2
Report2
)。