NHibernate的代理导致与数据绑定问题 [英] NHibernate proxy causing problems with databinding

查看:122
本文介绍了NHibernate的代理导致与数据绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到结果从NHibernate的查询一个gridview。如果列表中的第一项编辑以下异常被抛出:

I have a gridview that is bound to the result from an nhibernate query. If the first item in the list is edited the following exception is thrown:

System.Reflection.TargetException:对象不匹配目标类型

似乎该问题由以下事实数据绑定不能处理在列表是在列表中的其他项目的子类型的第一项引起的。

It appears that the problem is caused by the fact that databinding can't deal with the first item in the list being a subtype of the other items in the list.

什么是解决这个问题的一个很好的/正确的方法是什么?目前,我不得不关闭nhibernates代理。

What is a nice / correct way to solve this problem? Currently I have had to turn off nhibernates proxying.

编辑:我有另一对夫妇的解决方案:

I have another couple of solutions:

  • Clone everything in the list (http://steve-fair-dev.blogspot.com/2007/08/databind-object-does-not-match-target.html) - this doesn't work for me as the object doesn't implement ICloneable
  • change the order of items in the list so that the proxy isn't first (http://community.devexpress.com/forums/t/30797.aspx) - this is so hacky, I don't think I can stoop this low!

但这些感觉,虽然权...

But none of these feel right though...

推荐答案

的根本原因是由于在列表中的代理对象(从延迟加载),或者因为该列表是不均质(包含即使他们属于多种类型同一类层次结构)?与非齐次的数据集的问题是一个已知的限制。请参见和<一个href=\"http://stackoverflow.com/questions/333163/how-to-bind-a-gridview-to-a-list-of-multiple-types\">this.

Is the root cause due to a proxy object in the list (from lazy loading) or because the list isn't homogeneous (contains multiple types even if they belong to the same class hierarchy)? The problem with non-homogeneous data sets is a known limitation. See this and this.

我不认为还有比不使用数据绑定来填充网格中的其他解决方案。如果它是只读的是很容易。

I don't think there's a solution other than to not use databinding to populate the grid. That's easy enough if it's read-only.

这篇关于NHibernate的代理导致与数据绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆