Reputation: 2487
I have a property declared as type dynamic
public dynamic Data {get;set;}
later in some method the type of data becomes System.Collections.Generic.List
so if use Data.AsQueryable() i get "System.Collections.Generic.List<Entity1
does not contain a definition for 'AsQueryable' " error.
The result has to be converted to Iqueryble and i am using the methods defined in Dynamic.Linq.
How should i proceed?
Upvotes: 2
Views: 727
Reputation: 113402
Currently, dynamic
doesn't work well with extension methods.
7.6.5.2 Extension method invocations
...if the normal processing of the invocation finds no applicable methods, an attempt is made to process the construct as an extension method invocation. If expr or any of the args has compile-time type dynamic, extension methods will not apply
As is mentioned in this question, the static context (applicable using
directives) would have to be made available at run-time for every dynamic call to figure out which extension methods may apply, which is currently not implemented.
Have you tried calling the extension method as a 'normal' static method instead? E.g. (please modify if you intended to call a different method): System.Linq.Queryable.AsQueryable(Data)
Upvotes: 6