regular selectables.

This commit is contained in:
David Lebée
2018-03-21 20:00:46 -05:00
parent 3f5433ba53
commit 57fbee664e
5 changed files with 106 additions and 2 deletions
@@ -196,11 +196,31 @@ namespace PoweredSoft.DynamicLinq.Helpers
private static Expression CreateSelectExpression(IQueryable query, ParameterExpression parameter, SelectTypes selectType, string path)
{
if (!IsGrouping(query))
throw new NotSupportedException("Select without grouping is not supported yet.");
return CreateSelectExpressionRegular(query, parameter, selectType, path);
return CreateSelectExpressionForGrouping(query, parameter, selectType, path);
}
private static Expression CreateSelectExpressionRegular(IQueryable query, ParameterExpression parameter, SelectTypes selectType, string path)
{
if (selectType == SelectTypes.Path)
{
return ResolvePathForExpression(parameter, path);
}
else if (selectType == SelectTypes.PathToList)
{
var expr = ResolvePathForExpression(parameter, path);
var notGroupedType = expr.Type.GenericTypeArguments.FirstOrDefault();
if (notGroupedType == null)
throw new Exception($"Path must be a Enumerable<T> but its a {expr.Type}");
var body = Expression.Call(typeof(Enumerable), "ToList", new[] { notGroupedType }, expr);
return body;
}
throw new NotSupportedException($"unkown select type {selectType}");
}
private static bool IsGrouping(IQueryable query)
{
// TODO needs to be alot better than this, but it will do for now.