到目前为止,我使用了1,2,3
这样的串联Id字符串,并使用此查询在我的表格中进行了更新...
if exists( select ClientId from Clients where ClientId IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i))
begin
update Clients set IsDeleted=1 where ClientId IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i)
select 'deleted' as message
end
上述查询的linq-to-sql等价物是什么?任何建议......
答案 0 :(得分:1)
如果我已经理解你正在尝试做的事情,那么这样的事情应该有效。
var idsToDelete = ids.Split(",").Select(x => Convert.ToInt32(x));
var clientsToDelete = _DB.Clients.Where(x => idsToDelete.Contains(x.Id));
foreach(var client in clientsToDelete)
{
client.IsDeleted = true;
}
_DB.SubmitChanges();