Return a IQueryable<dynamic> with real dynamic and not as object. #6383
-
Hi everyone, I'm creating a core library https://github.com/KeyserDSoze/RystemV3, in my library I add the chance to serialize and deserialize Linq lambda expression for my repository framework library https://github.com/KeyserDSoze/RepositoryFramework to allow the communication over http for query pattern. All worked well until I wanted to add select and groupby to my core library. With groupby I created a work around but with select I found some issues.
The first method Select calls the second method with reflection to inject the return type of lambda expression as generic in Select<TSource, TResult>. The second method calls a third method that calls the linq method Select with a generic lambda expression (always with reflection).
and here the code (_context is entity of EF and sql is a mssql database)
Here the unit-test Second attempt, with dynamic
It returns the correct value but when I try to use MaxAsync the runtime doesn't find the method. I don't like this solution because returning a dynamic is a bad practice, but if it worked well I could have pass through, by the way it didn't work properly because the dynamic returns the real type and that type doesn't find MaxAsync method. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable' does not contain a definition for 'MaxAsync' So I tried differently, with new approach.
But, obviously, the same error happens (I pursued anyway).
does a chance exist to pursue what I want to do in C#? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'd say the problem is that you are missing the selector = Expression.Lambda(
Expression.Convert(selector.Body, typeof(object)),
selector.Parameters); (Also note that I had issues compiling your code, because of the use of Windows 1252 in SystemLinqExpressions.cs. If you want to use non-ASCII characters in your code, I'd suggest using UTF-8 instead.) |
Beta Was this translation helpful? Give feedback.
I'd say the problem is that you are missing the
Convert
. If I add the following line to yourSelect<TSource>
, then the test will pass for me (using anInMemory
database):(Also note that I had issues compiling your code, because of the use of Windows 1252 in…