Mewriick / Blazor.FlexGrid

GridView component for Blazor
MIT License
199 stars 35 forks source link

Entity Framework Child collections default to HashSet<T> and Master/Detail do not work #23

Closed drakeforte5 closed 5 years ago

drakeforte5 commented 5 years ago

I am using the db scaffolding and EF defaults to using Hashset.

This causes a casting error on the RunTimeTableAdapterProvider.cs (line 38). My work-around is to remove the casting altogether. ` public ITableDataAdapter CreateCollectionTableDataAdapter(object selectedItem, PropertyInfo propertyInfo) { var propertyType = propertyInfo.PropertyType.GenericTypeArguments[0]; var propertyValueGetter = propertyValueAccessorCache.GetPropertyAccesor(selectedItem.GetType()); var collectionValue = propertyValueGetter.GetValue(selectedItem, propertyInfo.Name); // EF is defaulting to HashSet and conversion to ICollection causes an exception - removed the "as ICollection" and now it works

        var dataAdapterType = typeof(CollectionTableDataAdapter<>).MakeGenericType(propertyType);
        var dataAdapter = Activator.CreateInstance(dataAdapterType,
            new object[] { collectionValue }) as ITableDataAdapter;

        return dataAdapter;
    }`