实体框架:是否有一种方法可以比较EntityObject的相等值? [英] Entity Framework: Is there a method to compare for equal values of EntityObject?
问题描述
有没有一种简单的方法可以比较两个EntityObject的值相等性。
我只是想检查所有数据库值是否相同,所以我不在乎EntityKey是否不同。
Is there a simple way to compare two EntityObjects for value-equality. I simply want to check if all the database-values are the same, so I don't care if the EntityKey is different.
这可能是内置的吗?还是我应该编写自己的方法。
Is this possible built-in? Or should I just write my own method.
我想Equals()不能按我的意愿工作?
I guess Equals() doesn't work as I want it here?
推荐答案
Equals()
检查引用是否相等,因此它对您没有帮助。
Equals()
checks for referential equality, so it wouldn't help you there.
看看这个问题: 比较两个实体框架的最佳方法是什么
2014年更新:
根据EF的当前状态,更完整的答案是您可以在代码优先模型中重写Equality运算符,以检查值是否相等。
UPDATE 2014:
A more complete answer, in line with the current state of EF, would be that you could override the Equality operator in a code-first model to provide a check for value-equality.
这篇关于实体框架:是否有一种方法可以比较EntityObject的相等值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!