How to bind a GridView to a list of multiple types? NHibernate proxy causing problems with databinding [From stack overflow]
2010-10-12 14:37
891 查看
NHibernate proxy causing problems with databinding
http://stackoverflow.com/questions/920227/nhibernate-proxy-causing-problems-with-databindingI 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:
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...
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.
If the filed is specified limited, you can use linq to select the fileds to generate a new list of obj to bind.
相关文章推荐
- How to reduce the size of logging database OR How to purge the old data from Logging Database
- 数据仓库Unable to get list of procedures from database meta-data: Table 'mysql.proc' doesn't exist
- How to implement common datastructures (List, Stack, Map) in plain Java - Tutorial
- How to delete a large number of data in SharePoint for List when refreshing data?
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- How to get the Values of Selected Row from a Gridview using ASP.NET
- Export Data from GridView to Excel, Word, HTML with C#
- How to Bind Silverlight DataGrid From IEnumerable of IDictionary by Transforming Each Dictionary Key
- 69.You need to generate a list of all customer last names with their credit limits from the CUSTOMER
- How to provide animation when calling another activity in Android?( from Stack overflow)
- How to eliminate the compile error "conversion from 'double ' to 'float ', possible loss of data"
- how to get Class of primitive datatypes array . Class.forName(int[]) throws exception
- Android - How to direct the audio data from MediaRecorder as the input of ffmpeg command via Pipe?
- How to Recover from a Lost or Deleted Datafile with Different Scenarios [ID 198640.1]
- How to populate the datagrid on background thread with data binding by using Visual C#
- How to setup multiple data sources with Spring and JPA
- How to sort an array of hashes into hashes with multiple values for a key?
- How to connect to MySQL database from Visual Studio VS2010 – problems with NET connectors
- How to export/import data with LOB type from one user/schema to another
- How to connect to MySQL database from Visual Studio VS2010 – problems with NET connectors