ACP
ACP

Reputation: 35268

Linq-To-Sql equivalent for this sql query

I thus far used concatenated Id string like 1,2,3 and updated in my table using this query...

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

What is the linq-to-sql equivalent for the above query? Any suggestion...

Upvotes: 0

Views: 94

Answers (1)

Kirschstein
Kirschstein

Reputation: 14868

If I've understood what you're trying to do correctly, something like this should work.

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();

Upvotes: 1

Related Questions