这是我的代码:
foreach (var r in rlist)
{
if (r.IndexOf("_") != -1)
{
int id = int.Parse(r.Split('_')[1]);
var x_tmp = (from x in db.tblX where x.x_id == my_id && x.x_id == id select x).First();
x_tmp.order = someNumber;
}
}
db.SaveChanges();
有没有办法重构这个?
答案 0 :(得分:0)
foreach(var x_tmp in db.tblX.Where(x => rlist.Where(r => r.indexOf("_") != -1).Select(r => Convert.ToInt32(r.Split('_')[1])).Contains(x.x_id)))
x_tmp = someNumber;
db.SaveChanges();
“my_id”的内容是什么?