@@ -63,9 +63,9 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
6363 return CallGenericWhereMethod ( source , filterQuery ) ;
6464 }
6565
66- public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , IEnumerable < string > columns )
66+ public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , IEnumerable < string > columns , IResourceFactory resourceFactory )
6767 {
68- return columns == null || ! columns . Any ( ) ? source : CallGenericSelectMethod ( source , columns ) ;
68+ return columns == null || ! columns . Any ( ) ? source : CallGenericSelectMethod ( source , columns , resourceFactory ) ;
6969 }
7070
7171 public static IOrderedQueryable < TSource > Sort < TSource > ( this IQueryable < TSource > source , SortQueryContext sortQuery )
@@ -342,7 +342,7 @@ private static Expression CreateTupleAccessForConstantExpression(object value, T
342342 return Expression . Property ( tupleCreateCall , "Item1" ) ;
343343 }
344344
345- private static IQueryable < TSource > CallGenericSelectMethod < TSource > ( IQueryable < TSource > source , IEnumerable < string > columns )
345+ private static IQueryable < TSource > CallGenericSelectMethod < TSource > ( IQueryable < TSource > source , IEnumerable < string > columns , IResourceFactory resourceFactory )
346346 {
347347 var sourceType = typeof ( TSource ) ;
348348 var parameter = Expression . Parameter ( source . ElementType , "x" ) ;
@@ -386,7 +386,7 @@ private static IQueryable<TSource> CallGenericSelectMethod<TSource>(IQueryable<T
386386 collectionElementType . GetProperty ( prop ) , Expression . PropertyOrField ( nestedParameter , prop ) ) ) . ToList ( ) ;
387387
388388 // { new Item() }
389- var newNestedExp = Expression . New ( collectionElementType ) ;
389+ var newNestedExp = resourceFactory . CreateNewExpression ( collectionElementType ) ;
390390 var initNestedExp = Expression . MemberInit ( newNestedExp , nestedBindings ) ;
391391 // { y => new Item() {Id = y.Id, Name = y.Name}}
392392 var body = Expression . Lambda ( initNestedExp , nestedParameter ) ;
@@ -419,7 +419,7 @@ private static IQueryable<TSource> CallGenericSelectMethod<TSource>(IQueryable<T
419419 nestedBindings . Add ( Expression . Bind ( propInfo , nestedBody ) ) ;
420420 }
421421 // { new Owner() }
422- var newExp = Expression . New ( nestedPropertyType ) ;
422+ var newExp = resourceFactory . CreateNewExpression ( nestedPropertyType ) ;
423423 // { new Owner() { Id = x.Owner.Id, Name = x.Owner.Name }}
424424 var newInit = Expression . MemberInit ( newExp , nestedBindings ) ;
425425
@@ -436,7 +436,8 @@ private static IQueryable<TSource> CallGenericSelectMethod<TSource>(IQueryable<T
436436 nestedBindings . Clear ( ) ;
437437 }
438438
439- var sourceInit = Expression . MemberInit ( Expression . New ( sourceType ) , sourceBindings ) ;
439+ var newExpression = resourceFactory . CreateNewExpression ( sourceType ) ;
440+ var sourceInit = Expression . MemberInit ( newExpression , sourceBindings ) ;
440441 var finalBody = Expression . Lambda ( sourceInit , parameter ) ;
441442
442443 return source . Provider . CreateQuery < TSource > ( Expression . Call (
0 commit comments