C# 将旧查询格式化为LINQ语句
下面的查询是我从一个旧应用程序继承的,它向数据库中存储的excel添加了2个属性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
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++;
}
我想:)谢谢你的回答。我现在不能测试它,因为其他工作已经通过了这个测试。我会尽快测试的。谢谢你的回答。我现在不能测试它,因为其他工作已经通过了这个测试。我会尽快测试它。