Skip to content

Commit 1b8b6cb

Browse files
committed
fix(IQueryableExt): clean up extension
1 parent 99f623d commit 1b8b6cb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
125125
throw new JsonApiException("400", $"Could not cast {filterQuery.PropertyValue} to {property.PropertyType.Name}");
126126
}
127127
}
128-
public static IQueryable<TSource> Select<TSource>(this IQueryable source, string[] columns)
128+
public static IQueryable<dynamic> Select<TSource>(this IQueryable<TSource> source, string[] columns)
129129
{
130130
var sourceType = source.ElementType;
131131

@@ -137,13 +137,13 @@ public static IQueryable<TSource> Select<TSource>(this IQueryable source, string
137137
var bindings = columns.Select(column => Expression.Bind(
138138
resultType.GetProperty(column), Expression.PropertyOrField(parameter, column)));
139139

140+
// { new Model () { Property = model.Property } }
140141
var body = Expression.MemberInit(Expression.New(resultType), bindings);
141142

142-
var selector = Expression.Lambda(body, parameter);
143+
// { model => new TodoItem() { Property = model.Property } }
144+
var selector = Expression.Lambda<Func<TSource, dynamic>>(body, parameter);
143145

144-
return source.Provider.CreateQuery<TSource>(
145-
Expression.Call(typeof(Queryable), "Select", new Type[] { sourceType, resultType },
146-
source.Expression, Expression.Quote(selector)));
146+
return source.Select(selector);
147147
}
148148
}
149149
}

0 commit comments

Comments
 (0)