Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 为什么可以';我的nhibernate方法不能找到我的字段吗?_.net_Nhibernate - Fatal编程技术网

.net 为什么可以';我的nhibernate方法不能找到我的字段吗?

.net 为什么可以';我的nhibernate方法不能找到我的字段吗?,.net,nhibernate,.net,Nhibernate,所以我有一个(VB,抱歉)对象: 最大的谜团是,当我从数据库加载对象时,在Equals()中,other.foo始终为零,即使foo()中的值是正确的 这怎么可能 Equals方法的另一个版本是: Private Overloads Function Equals(ByVal other as Foo) as Boolean Implements IEquatable(Of Foo).Equals Return Me.foo.Equals(other.foo) End Function 在

所以我有一个(VB,抱歉)对象:

最大的谜团是,当我从数据库加载对象时,在
Equals()
中,
other.foo
始终为零,即使
foo()
中的值是正确的

这怎么可能

Equals方法的另一个版本是:

Private Overloads Function Equals(ByVal other as Foo) as Boolean Implements IEquatable(Of Foo).Equals
  Return Me.foo.Equals(other.foo)
End Function

在这个版本中,Me.foo和
other.foo
都是零。

几个小时后,我发现object type Equals()方法是罪魁祸首,可能是因为DirectCast-ed实例绕过了代理

在第二个例子中,问题是私有实现(!谁知道!)绕过了代理


因此,这个故事的寓意似乎是:避免DirectCast,避免私有接口实现。:-)

似乎最好的做法是根本不使用字段,至少不在Equals()中使用。
Private Overloads Function Equals(ByVal other as Foo) as Boolean Implements IEquatable(Of Foo).Equals
  Return Me.foo.Equals(other.foo)
End Function