NHibernate proxy causing problems with databinding

后端 未结 5 1320
庸人自扰
庸人自扰 2021-01-20 05:34

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.Refle

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 06:23

    Maybe too late, but I'd just like to throw this into the ring, here is a solution that I've used for this.

    It is also called 'SafeBindingList' like the other suggestion above, but, it does not 'clone' objects to solve the problem. It looks at the objects in the list, then if none proxied, the list is returned unmodified. If one or more objects are proxied, it adds an empty proxy to the non-proxied objects, thus making them all the same type.

    So, instead returning a List[T] to bind to, use SafeBindingList[T] to ensure all objects have the same type.

    This is updated for the version of Castle used with NH2.0.1: http://code.google.com/p/systembusinessobjects/source/browse/trunk/System.BusinessObjects.Framework/Data/SafeBindingLists.cs

    Also, credit goes to the original code and poster: https://forum.hibernate.org/viewtopic.php?t=959464&start=0&postdays=0&postorder=asc&highlight=

提交回复
热议问题