NHibernate代理引起数据绑定问题 [英] NHibernate proxy causing problems with databinding

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

问题描述

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



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



似乎问题是由于数据绑定无法处理列表中的第一个项目,而是其他项目的子类型在列表中。



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



编辑:我有另外两个解决方案:





b $ b

解决方案

由于列表中的代理对象(从延迟加载)导致根本原因,或因为列表不是同构的包含多个类型,即使它们属于同一个类层次结构)?非均匀数据集的问题是已知的限制。请参阅这个



我不认为除了不使用数据绑定来填充网格之外,还有一个解决方案。这很容易,只要它是只读的。


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: Object does not match target type

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.

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

Edit: I have another couple of solutions:

But none of these feel right though...

解决方案

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天全站免登陆