Entity know-how question. Given the following code:
...
var entitiesToRemove = dbSet.Where (entity => entity.TimeToLive > 5);
dbSet.RemoveRange(entitiesToRemove);
var resultEntities = dbSet.Where(entity => /* some condition that will also match before deleted entities*/);
...
Question: Will the beforehand deleted entities also be included in resultEntities or not? Do I've to call DbContext.SaveChanges after dbSet.RemoveRange ?
Thx
You need to do dbcontext.SaveChanges() before doing further processing. In dbSet.RemoveRange(entitiesToRemove), EF just have marked those entities for deletion. Which will reflect on db only after you call the SaveChanges().
Yes, I think DbContext.SaveChanges should go after dbSet.RemoveRange
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With