views:

24

answers:

1

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...

A: 

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();
Kirschstein
@Kirschstein ya you got it right....
Pandiya Chendur