//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();
The only thing that solved the problem was an explicit loop:
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();