//A query to a local object
var deletionCommands = commands
.Where(a => a.Operation != Operation.Addition)
.Select(a => new { a.Prestador.cod_prestador, a.Prestador.cod_desdobramento })
;
//A Linq-To-SQL query
var toDelete = db.Prestadors
.Where(a => deletionCommands.Contains(new { a.cod_prestador, a.cod_desdobramento }))
;
db.Prestadors.DeleteAllOnSubmit(toDelete);
db.SubmitChanges();
唯一解决问题的是一个显式循环:
foreach (var command in commands)
{
if(command.Operation != Operation.Addition)
{
var toDelete = db.Prestadors
.Where(a =>
a.cod_prestador == command.Prestador.cod_prestador &&
a.cod_desdobramento == command.Prestador.cod_desdobramento
);
db.Prestadors.DeleteAllOnSubmit(toDelete);
}
}
db.SubmitChanges();