11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Linq . Expressions ;
45using System . Reflection ;
@@ -125,8 +126,11 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
125126 throw new JsonApiException ( "400" , $ "Could not cast { filterQuery . PropertyValue } to { property . PropertyType . Name } ") ;
126127 }
127128 }
128- public static IQueryable < dynamic > Select < TSource > ( this IQueryable < TSource > source , string [ ] columns )
129+ public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , IEnumerable < string > columns )
129130 {
131+ if ( columns == null || columns . Count ( ) == 0 )
132+ return source ;
133+
130134 var sourceType = source . ElementType ;
131135
132136 var resultType = typeof ( TSource ) ;
@@ -141,9 +145,11 @@ public static IQueryable<dynamic> Select<TSource>(this IQueryable<TSource> sourc
141145 var body = Expression . MemberInit ( Expression . New ( resultType ) , bindings ) ;
142146
143147 // { model => new TodoItem() { Property = model.Property } }
144- var selector = Expression . Lambda < Func < TSource , dynamic > > ( body , parameter ) ;
145-
146- return source . Select ( selector ) ;
148+ var selector = Expression . Lambda ( body , parameter ) ;
149+
150+ return source . Provider . CreateQuery < TSource > (
151+ Expression . Call ( typeof ( Queryable ) , "Select" , new Type [ ] { sourceType , resultType } ,
152+ source . Expression , Expression . Quote ( selector ) ) ) ;
147153 }
148154 }
149155}
0 commit comments