且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NHibernate的:原因压倒一切的Equals和GetHash code

更新时间:2023-01-23 17:07:01

重载等于 GetHash code 方法是很重要的,如果你正在使用多个会话,独立的实体,无状态的会话或集合(见西斯托·赛斯的回答的例子!)。

Overloading the Equals and GetHashCode methods is important if you are working with multiple sessions, detached entities, stateless sessions or collections (see Sixto Saez's answer for an example!).

在同一个会话范围的标识映射将确保你只拥有同一个实体的单个实例。然而,有一个实体具有相同的实体的代理进行比较的可能性(见下文)。

In the same session scope identity map will ensure that you only have a single instance of the same entity. However, there is the possibility of comparing an entity with a proxy of the same entity (see below).