1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using System . Linq . Expressions ;
4
5
using System . Reflection ;
@@ -125,8 +126,11 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
125
126
throw new JsonApiException ( "400" , $ "Could not cast { filterQuery . PropertyValue } to { property . PropertyType . Name } ") ;
126
127
}
127
128
}
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 )
129
130
{
131
+ if ( columns == null || columns . Count ( ) == 0 )
132
+ return source ;
133
+
130
134
var sourceType = source . ElementType ;
131
135
132
136
var resultType = typeof ( TSource ) ;
@@ -141,9 +145,11 @@ public static IQueryable<dynamic> Select<TSource>(this IQueryable<TSource> sourc
141
145
var body = Expression . MemberInit ( Expression . New ( resultType ) , bindings ) ;
142
146
143
147
// { 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 ) ) ) ;
147
153
}
148
154
}
149
155
}
0 commit comments