We have some projections that return an entity as a property. When grouping on those properties, despite the entity being the same, it will group based on reference and so we end up with two groups for what is the same entity.
As a solution I've overridden GetHashCode and Equals on the entity with;
public override int GetHashCode()
{
return DealerId == 0 ? base.GetHashCode() : DealerId.GetHashCode();
}
public override bool Equals(object obj)
{
var x = obj as Dealer;
if (x == null)
return false;
if (DealerId == 0 && x.DealerId == 0)
return ReferenceEquals(this, x);
return DealerId == x.DealerId;
}
Which works fine, however, is there another solution? As this solution would require I override these methods for all entities in my model.
Edited by smi-dan - 20-Aug-2013 at 10:13am