假设我的数据库中有一个简单的DTO对象,并且Id是一个recordId绝对唯一的,那么执行以下操作是个好主意吗?
public class DTO
{
public int Id { get; set; }
public override bool Equals(object obj)
{
return (Id == ((DTO)obj).Id);
}
public override int GetHashCode()
{
return Id;
}
}
Run Code Online (Sandbox Code Playgroud)
我怀疑它的原因是因为我没有在我周围的代码中看到它,而不是代码
int hash = 7;
hash = 89 * hash + pageId.hashCode();
hash = 89 * hash + recordId;
return hash;
Run Code Online (Sandbox Code Playgroud)