i have implemented Custom Binding.I get error like "object reference not set to an instance of an object" when Group a column which is complex Type(Order.Name).
public static IEnumerable<AggregateFunctionsGroup> BuildInnerGroup<T, TObject>(IEnumerable<TObject> group, Func<TObject, T> groupSelector, Func<IEnumerable<TObject>, IEnumerable> innerSelector)
{
return group.GroupBy(groupSelector)
.Select(i => new AggregateFunctionsGroup
{
Key = i.Key,
Items = innerSelector(i)
});
}
public static Func<IEnumerable<TObject>, IEnumerable<AggregateFunctionsGroup>> BuildGroup<T, TObject>(Func<TObject, T> groupSelector, Func<IEnumerable<TObject>, IEnumerable<AggregateFunctionsGroup>> selectorBuilder)
{
var tempSelector = selectorBuilder;
return g => g.GroupBy(groupSelector)
.Select(c => new AggregateFunctionsGroup
{
Key = c.Key,
HasSubgroups = true,
Items = tempSelector.Invoke(c).ToList()
});
}
public static IEnumerable<AggregateFunctionsGroup> ApplyGrouping<T>(this IQueryable<T> data, IList<GroupDescriptor> groupDescriptors)
{
Func<IEnumerable<T>, IEnumerable<AggregateFunctionsGroup>> selector = null;
foreach(var descriptor in groupDescriptors.Reverse())
{
var tempDescriptor = descriptor;
if(selector == null)
selector = g => BuildInnerGroup(g.Select(p => p), p => p.GetType().GetProperty(tempDescriptor.Member).GetValue(p, null), i => i.ToList());
else
selector = BuildGroup(p => p.GetType().GetProperty(tempDescriptor.Member).GetValue(p, null), selector);
}
return selector != null
? selector.Invoke(data).ToList()
: null;
}
For simple field it is working well.When I Group a field with complex type(Order.Name) i get the above error in ApplyGrouping function.In debug mode i see in ApplyGrouping function,the tempDescriptor.Member property value is Order.Name.I need to Split the property on dot(.) and make the grouping(like in the sorting which i already implemented for complex type). Please give a suggestion for grouping.i post the same issue in StackOverflow
http://stackoverflow.com/questions/22023649/telerik-grid-custom-bindinggrouping-on-complex-property
Sabbir
public static IEnumerable<AggregateFunctionsGroup> BuildInnerGroup<T, TObject>(IEnumerable<TObject> group, Func<TObject, T> groupSelector, Func<IEnumerable<TObject>, IEnumerable> innerSelector)
{
return group.GroupBy(groupSelector)
.Select(i => new AggregateFunctionsGroup
{
Key = i.Key,
Items = innerSelector(i)
});
}
public static Func<IEnumerable<TObject>, IEnumerable<AggregateFunctionsGroup>> BuildGroup<T, TObject>(Func<TObject, T> groupSelector, Func<IEnumerable<TObject>, IEnumerable<AggregateFunctionsGroup>> selectorBuilder)
{
var tempSelector = selectorBuilder;
return g => g.GroupBy(groupSelector)
.Select(c => new AggregateFunctionsGroup
{
Key = c.Key,
HasSubgroups = true,
Items = tempSelector.Invoke(c).ToList()
});
}
public static IEnumerable<AggregateFunctionsGroup> ApplyGrouping<T>(this IQueryable<T> data, IList<GroupDescriptor> groupDescriptors)
{
Func<IEnumerable<T>, IEnumerable<AggregateFunctionsGroup>> selector = null;
foreach(var descriptor in groupDescriptors.Reverse())
{
var tempDescriptor = descriptor;
if(selector == null)
selector = g => BuildInnerGroup(g.Select(p => p), p => p.GetType().GetProperty(tempDescriptor.Member).GetValue(p, null), i => i.ToList());
else
selector = BuildGroup(p => p.GetType().GetProperty(tempDescriptor.Member).GetValue(p, null), selector);
}
return selector != null
? selector.Invoke(data).ToList()
: null;
}
For simple field it is working well.When I Group a field with complex type(Order.Name) i get the above error in ApplyGrouping function.In debug mode i see in ApplyGrouping function,the tempDescriptor.Member property value is Order.Name.I need to Split the property on dot(.) and make the grouping(like in the sorting which i already implemented for complex type). Please give a suggestion for grouping.i post the same issue in StackOverflow
http://stackoverflow.com/questions/22023649/telerik-grid-custom-bindinggrouping-on-complex-property
Sabbir