I have the following and looking for a more efficient way of deleting vs looping through the records and then deleting each one at a time (note using Dbset):
var wcd = dbContext.ProgramDetails.Where(p => p.Id == Id);
foreach (var wc in wcd.ToList())
{
dbContext.ProgramDetails.Remove(wc);
}
dbContext.SaveChanges();
Also say if we have 1 record that is as following:
var pg = dbContext.Program.Where(p => p.Id == Id && Name == FName);
What is the best way of deleting this one record?
tried the following but gave an error:
var pg = dbContext.Program.Where(p => p.Id == Id && Name == FName);
dbContext.Program.Remove(wc);
Then I resorted to doing a foreach for deleting just one record as I have shown above that is not the most efficient for just 1 record.