Next allow the possibility to specify the class type to group by :)
This commit is contained in:
parent
b624797330
commit
9db5d74284
@ -81,7 +81,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
||||
{
|
||||
// EXPRESSION
|
||||
var parameter = Expression.Parameter(type, "t");
|
||||
var partExpressions = new List<Expression>();
|
||||
var partExpressions = new List<(Expression expression, string propertyName)>();
|
||||
|
||||
var fields = new List<(Type type, string propertyName)>();
|
||||
|
||||
@ -90,17 +90,27 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
||||
{
|
||||
var partExpression = ResolvePathForExpression(parameter, part.path);
|
||||
fields.Add((partExpression.Type, part.propertyName));
|
||||
partExpressions.Add(partExpression);
|
||||
partExpressions.Add((partExpression, part.propertyName));
|
||||
});
|
||||
|
||||
var anonymousType = TypeHelpers.CreateSimpleAnonymousType(fields);
|
||||
|
||||
|
||||
/*
|
||||
var constructorTypes = fields.Select(t => t.type).ToArray();
|
||||
var constructor = anonymousType.GetConstructor(constructorTypes);
|
||||
var newExpression = Expression.New(constructor, partExpressions);
|
||||
var genericMethod = Constants.GroupByMethod.MakeGenericMethod(type, anonymousType);
|
||||
var lambda = Expression.Lambda(newExpression, parameter);
|
||||
var groupByExpression = Expression.Call(genericMethod, query.Expression, lambda);
|
||||
var result = query.Provider.CreateQuery(groupByExpression);*/
|
||||
|
||||
var ctor = Expression.New(anonymousType);
|
||||
var bindings = partExpressions.Select(partExpression => Expression.Bind(anonymousType.GetProperty(partExpression.propertyName), partExpression.expression)).ToList();
|
||||
var mi = Expression.MemberInit(ctor, bindings.ToArray());
|
||||
var lambda = Expression.Lambda(mi, parameter);
|
||||
var genericMethod = Constants.GroupByMethod.MakeGenericMethod(type, anonymousType);
|
||||
var groupByExpression = Expression.Call(genericMethod, query.Expression, lambda);
|
||||
var result = query.Provider.CreateQuery(groupByExpression);
|
||||
return result;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
||||
{
|
||||
CreatePropertyOnType(dynamicType, field.name, field.type);
|
||||
});
|
||||
CreateConstructorWithAllPropsOnType(dynamicType, fields);
|
||||
// CreateConstructorWithAllPropsOnType(dynamicType, fields);
|
||||
var ret = dynamicType.CreateTypeInfo();
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user