public class TestEntity : IEquatable<TestEntity> { private Guid _id; private string _name;public Guid ID { get { return _id; } set { _id = value; } } public string Name { get { return _name; } set { _name = value; } // This causes bad performance on AddNew it seems, remove IEquatable // implementation to see the difference. Overriding Equals(object) // causes the same thing public bool Equals(TestEntity other) { return ((object)other != null && this.ID.Equals(other.ID); } }
If you override Equals on a class, make DARN SURE you also override the implementation of GetHashCode appropriately or you'll have serious issues with HashTables (and some other collections)... just FYI. In your case, you should be doing returning the GetHashCode of the ID Guid. The real difference between the two calls you've paste in is that one is working against an uninitialized Guid for all the comparisons... so they are ALL the "same" according to you Equals implementation. That doesn't seem like an indictement against List<T> with a class that implements Equals, that seems like a bad test case. -- "We do not have the luxury of making that risky assumption that people will not be affected by the potential change. I know this can be frustrating for you as it is for us. Thanks for your understanding in this matter.." --Some misguided soul at Microsoft Marc C. Brooks http://musingmarc.blogspot.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
