Linq to sql 此Sql查询的Linq到Sql等效项
到目前为止,我使用了连接的Id字符串,如Linq to sql 此Sql查询的Linq到Sql等效项,linq-to-sql,string,split,sql,Linq To Sql,String,Split,Sql,到目前为止,我使用了连接的Id字符串,如1,2,3,并使用此查询在我的表中进行了更新 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(
1,2,3
,并使用此查询在我的表中进行了更新
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到sql的等价物是什么?任何建议…如果我已经理解了您试图正确执行的操作,类似的操作应该会奏效
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();