I have a method that receive the IDs of some rows to delete. I am using a code like this:
public bool delete(IEnumerable<long> paramIeId)
{
using(myContext)
{
foreach(long iterator in paramIeId)
{
nyDbContext.Remove(new MyType(){ID = iterator});
}
}
}
It works fine because delete the rows when exists. But If there area 1 or more rows that doesn't exist then I get an exception and no one rows are delete, although some of them exists.
If I do this query in T-SQL I don't have problems, the database delete the exisiting rows and igonre the no exisiting rows because at the end I want to delete them so if another process deleted them for me, no problem.
I could handle the optimistic concurrency exception refreshing the dbContextfrom database, but I think that it is to do extra queries that they could be avoid.
Is there any way that EF works like T-SQL? If I try to delete a row that doen't exists, ignore it and delete the rest of the rows.
Thanks.