NHibernate proxy causes data binding problems

I have a gridview related to the result of a nhibernate request. If the first item in the list is edited, the following exception is thrown:

System.Reflection.TargetException: Object does not match target type

The problem seems to be caused by the fact that data binding cannot process the first item in the list, which is a subtype of the other items in the list.

What is a good / right way to solve this problem? Currently, I had to disable nhibernates proxying.

Edit: I have a few more solutions:

But none of them are feeling well, though ...

+3
source share
5 answers

Is the reason because of the proxy object in the list (from lazy loading) or because the list is not homogeneous (contains several types, even if they belong to the same class hierarchy)? The problem with heterogeneous datasets is a known limitation. See this and this .

, , , . , .

+2

. MVVM , .

0

. , , . . add.SetFetchMode( "", FetchMode.Join). NHibernate , .

0

, . , , ( NotificationList) .

private IList<IParameter> _parameters = new List<IParameter>();  
get  
{  
    return new NotificationList<IParameter>(_parameters);  
}

, ​​ .

public class NotificationList<T> : IList, IList<T>    
{
    IList<T> myList;
    public NotificationList(IList<T> list)
    {
        myList = list;
    }
    int IList.Add(object item)
    {
        myList.Add ((T) item);
    } 
    // implement both IList<T> and IList
    // ...
}

, , , , , . , , . . this Hibernate, NHibernate.
() :

HasMany(x => x.Parameters)
       .Cascade.All()
       .Access.CamelCaseField(Prefix.Underscore);
0

Source: https://habr.com/ru/post/1709287/


All Articles