我有以下sql语句,我试图进入LINQ
update MyTable
set MyValue = Convert(int, MyValue) + 1
output deleted.MyValue
where MyKey = 'Number'
我已经搜索过高和低,并且无法在LINQ中找到一种方法来执行此SQL语句并获得正确的结果。
答案 0 :(得分:1)
您可以尝试以下操作:
var queryMyTable =
from t in db.MyTable
where t.MyKey == "Number"
select t;
foreach (var t in queryMyTable)
{
Console.WriteLine(t.MyValue); // equivalent to output deleted.MyValue
t.MyValue = Convert.ToDouble((Convert.ToInt32(t.MyValue) + 1));
}
db.SubmitChanges();