deleting the miltiple records vb.net 3.5
-
i have a string "1,2,3,4,5,6" these are the ids , i want to delete the record which have these ids , in sql we use in predicate. can i use the in predicate in LINQ. I dopn't want to use the loops here.
Without using loops this can be done:
var IDs = @"1,2,3,4,5,6";
var IDarray = IDs.Split(",");
var toDelete = from T in db.Table
where IDarray.Contains(T.ID)
select T;
db.Table.DeleteAllOnSubmit(toDelete);
db.SubmitChanges();Unfortunately this results in six delete commands on the server, so it isn't as efficient as a single SQL delete command. Other people have been developing extensions to LINQ for deletes and updates which you could try out. See Aney's blog[^] or Zhao's blog[^] for more info.
'Howard
modified on Saturday, August 9, 2008 10:59 AM