What should I call a method checking if two entities refers the same db entity?
I have entity objects that are synchronized with a database. I commonly use these entities in three different comparisons:
- Check if two entity objects are the same CLR object.
- Check if all properties of two entity objects are equal.
- Check if two entity objects refer to the same database entity, even if some properties differ.
For 1 I use Object.ReferenceEquals(). For 2 I overwrite Equals() checking all properties. For 3 I have been a bit inconsistent. Some entities have a "Match" method some have a "IsSame" method. The logic of the method compares their primary key and if has not been assigned by the database yet, their secondary key (if they have one).
A lot of code scenarios would be easier if I used Equals for comparing keys (e.g. I could check a list just using Contains()), but I would find it confusing, if Equals only compared th开发者_如何学Goe keys and didn't check all properties.
My scenario is an N-Tier system with self-tracking-entities. I often need to update a list of entities or similar with an updated entity arriving from another tier.
Is there a consensus for naming a method checking if two entities refers to the same logical entity? KeyEquals()? SameEntity()?
DbEquivalent()?
精彩评论