Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.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# 将旧查询格式化为LINQ语句_C#_Sql_Linq_C# 4.0 - Fatal编程技术网

C# 将旧查询格式化为LINQ语句

C# 将旧查询格式化为LINQ语句,c#,sql,linq,c#-4.0,C#,Sql,Linq,C# 4.0,下面的查询是我从一个旧应用程序继承的,它向数据库中存储的excel添加了2个属性 SELECT row_number() over(order by id) as num , [id] as mailsort , 0 as pages , [xmlRecord].query('/sst-statement/*') FROM dbo.RPA200_preproc AS [sst-statement] WHERE rpatype = 201 ORDER BY id

下面的查询是我从一个旧应用程序继承的,它向数据库中存储的excel添加了2个属性

SELECT 
   row_number() over(order by id) as num
   , [id] as mailsort
   , 0 as pages
   , [xmlRecord].query('/sst-statement/*') 
FROM  dbo.RPA200_preproc AS [sst-statement] 
WHERE rpatype = 201 
ORDER BY id for xml auto
返回以开头的XML

<sst-statement num="1" mailsort="32" pages="0">

现在,需要将SQL转换为LINQ语句。这可能与此查询类似,还是从数据库检索XML然后更改XML更好

SELECT
row_number() over(order by id) as num,
[id] as mailsort,
0 as pages,
[xmlRecord].query('/sst-statement/*')
FROM  dbo.RPA200_preproc as [sst-statement]
where rpatype = 201
order by id for xml auto
变成

int i=0;
var Query =
FROM I in dbo.RPA200_preproc
WHERE rpatype = 201
order by id
SELECT I.id;
foreach(var Item in Query)
{
    new XElement("sst-statement", new XAttribute("num", i), new XAttribute("mailsort" = Item), new XAttribute("Pages",(int)0));
    i++;
}
我想:)

变成

int i=0;
var Query =
FROM I in dbo.RPA200_preproc
WHERE rpatype = 201
order by id
SELECT I.id;
foreach(var Item in Query)
{
    new XElement("sst-statement", new XAttribute("num", i), new XAttribute("mailsort" = Item), new XAttribute("Pages",(int)0));
    i++;
}

我想:)

谢谢你的回答。我现在不能测试它,因为其他工作已经通过了这个测试。我会尽快测试的。谢谢你的回答。我现在不能测试它,因为其他工作已经通过了这个测试。我会尽快测试它。