Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

后端 未结 1 981
说谎
说谎 2020-12-03 09:42

I am working with .NET4.5 and VS2013, I have this query that gets dynamic result from db.

dynamic topAgents = this._dataContext.Sql(
    \"sele         


        
相关标签:
1条回答
  • 2020-12-03 10:17

    The problem is that topAgents is dynamic - so your ToList() call is dynamic, and so is Select. That has issues that:

    1. you can't use lambda expressions for dynamic calls like this;
    2. dynamic calls don't find extension methods anyway.

    Fortunately, the operations don't need to be dynamic just because the element type is dynamic. You could use:

    IEnumerable<dynamic> topAgents = ...;
    

    ... or just use var. Both of those should be fine.

    0 讨论(0)
提交回复
热议问题