Another solution would be to implement the
IEquatable<EQUentity>
and
IEquatable
interfaces.
Thus:
using System.Collections.Generic
public partial class EQUentity : IEquatable<EQUentity>, IEquatable
{
public int ID_EQU { get; set; }
public string CODE_EQU { get; set; }
public string DESIGNATION_EQU { get; set; }
public bool Equals(EQUentity other)
{
}
override bool Equals(object obj)
{
if (!obj is EQUentity) {
return false;
}
if (this.ReferenceEquals(obj)) {
return true;
}
return this.Equals((EQUentity)obj);
}
}
Here is the idea. The only thing that remains to be done is to define the logic to determine whether both instances are equal or not.
And the cherry on the cake : you can even define
==
and
!=
operators to be able to write:
if (leftEntity == rightEntity)
This way:
public static bool operator ==(EQUentity left, EQUentity right)
{
return left.Equals(right);
}
public static bool operator !=(EQUentity left, EQUentity right)
{
return !left.Equals(right);
}
Hope this helps.