To equals and hashcode or not on entity classes, that is the question

后端 未结 2 704
灰色年华
灰色年华 2021-01-18 09:48

I have been trying to reason about the best way to handle whether it is generally good practice to implement hashcode and equals on entities (I mean entity in the general se

2条回答
  •  青春惊慌失措
    2021-01-18 10:05

    There are times when you want Equals to compare all properties and times when you want Equals to be just the key. We've had a lot more success using helper classes that are explicit so there isn't ambiguity as to what's being compared.

    ByKeyComparer.Equals...
    ByPropertiesComparer.Equals...
    

    or

    Entity1.EqualsByKey...
    Entity1.EqualsByProperties...
    

提交回复
热议问题