I know that with both ways it is possible to delete. They have the same function?
Yes.
I can use any one at any time?
Yes.
Are there any specific cases for use of any?
Remove() checks some more consistencies, such as the materialization of the set itself (main entity and aggregated entities) and the state of the properties, with due detection of the fields that have been changed, but there is little difference between them. When it comes to exclusion, maintaining field change status is not so important.
For checking things out, Remove()
is most recommended to be used. For example, if the operation involves cascading deletion and the key can be null in the entity that will not be deleted, use EntityState.Deleted
can leave the record orphaned, because there is no complete verification of the aggregation, and yes, only the record marked for deletion.