I know that with both forms you can exclude. Do they have the same function?
Yes.
Can I use any one at any time?
Yes.
Are there any specific cases to use?
Remove () checks for some additional consistencies, such as the actual materialization of the set (main entity and aggregate entities) and the properties state, with due detection of the fields that have been changed, but there is no big difference between them. When it comes to exclusion, maintaining state of field change is not so important.
For checking too many things, Remove()
is more recommended to use. For example, if the operation involves exclusion cascade and the key may be null in the entity that will not be deleted, using EntityState.Deleted
may leave the orphaned record because there is no complete verification of the aggregation, but only the record marked for deletion .