Skip to content

Method groups inside Projectables #62

@cyril265

Description

@cyril265

Hey, awesome library. I just replaced LinqKit with it 😃

There might be an issue with method groups inside projectables.
If you do the following inside a Projectable it fails because method groups are converted to Func<> instead of Expression<> :

entity.Collection.Select(MapChildren) // Collection is an IEnumerable and MapChildren is another Projectable

Error message:

System.ArgumentException: Expression of type 'System.Func`2[Participant,Substitutes.SubstitutedParticipantRecord]' cannot be used for parameter of type 'System.Linq.Expressions.Expression`1[System.Func`2[Participant,Substitutes.SubstitutedParticipantRecord]]' of method 'System.Linq.IQueryable`1[Substitutes.SubstitutedParticipantRecord] Select[Participant,SubstitutedParticipantRecord](System.Linq.IQueryable`1[Participant], System.Linq.Expressions.Expression`1[System.Func`2[Participant,Substitutes.SubstitutedParticipantRecord]])' (Parameter 'arg1')
   at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0, Expression arg1)

So it's kind of a C#/EF limitation but it might be worth rewritting Projectables that use method groups. Also Rider for example offers a quick fix to replace calls with method group. Which makes it even more confusing/error prone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions