I'm extend a SELECT function in order to select custom fields of SELECT from list of string.
The function you will see in images bellow is: SelectExtend() at line 201.
When i'm running in debug mode. The query value in Watch window are difference when i run over line 201.
I have captured the image about before and after calling the SelectExtend() function.
Anyone can explain to me why the query return "System.Data.Entity.Infrastructure.DbQuery", not "Select [Project1].[ID], ...."?
I want the query return as "Select [Project1].[ID], ...."
Thanks for reading.
And here are source code of function "SelectExtend()"
public static IQueryable<T> SelectExtend<T>(this IQueryable<T> source, List<string> fields)
{
if (fields == null || fields.Count <= 0)
throw new ArgumentException("'fields' can not be null or empty.");
var parameter = Expression.Parameter(source.ElementType, "x");
var body = Expression.MemberInit(
Expression.New(typeof(T)),
fields.Select(field => Expression.Bind(
typeof(T).GetProperty(field),
Expression.PropertyOrField(parameter, field))
)
);
var selector = Expression.Lambda(body, parameter);
var expression = Expression.Call(
typeof(Queryable)
, "Select"
, new[] { source.ElementType, selector.Body.Type }
, source.Expression
, Expression.Quote(selector)
);
return source.Provider.CreateQuery<T>(expression);
}