c# - Why is my LINQ Expression with multiple parameters not compiling? -


i want extend linq expression (dosomething)

using linqkit; // system.linq.expressions.expression<>.invoke()  public class expressions {   public static system.linq.expressions.expression<     system.func<int, int, int, int, bool>>       dosomething =         (a, b, c, d) => false; }  public class expressiontester {   public expressiontester()   {     expressions.dosomething.invoke(1, 2, 3, 4);   } } 

with additional parameter not compile:

public class expressions {   public static system.linq.expressions.expression<     system.func<int, int, int, int, int, bool>>       dosomething =         (a, b, c, d, e) => false; }  public class expressiontester {   public expressiontester()   {     expressions.dosomething.invoke(1, 2, 3, 4, 5);   } }  best overloaded method match 'system.linq.expressions.expression.invoke(system.linq.expressions.expression, params system.linq.expressions.expression[])' has invalid arguments error cs1503: argument 1: cannot convert 'int' 'system.linq.expressions.expression' error cs1503: argument 2: cannot convert 'int' 'system.linq.expressions.expression' error cs1503: argument 3: cannot convert 'int' 'system.linq.expressions.expression' error cs1503: argument 4: cannot convert 'int' 'system.linq.expressions.expression' error cs1503: argument 5: cannot convert 'int' 'system.linq.expressions.expression' 

is there undocumented limitation number of parameters?

:edit

thanks answer of unknown author deleted answer 10 seconds later see linqkit compiled .net 3.5 whereas caused limitation of system.func<> 4 parameters.

:edit2

the suggested compile().invoke() workaround not working in cases in connection queries (which need). created fork linqkit project , added code support 16 parameters:

https://github.com/virustrinity/linqkit/commit/bcca71978ef3fbb988d242463adfbc4e9cd42565

when add fifth parameter, you're binding different invoke 1 in linqkit:

public static tresult invoke<t1, t2, t3, t4, tresult> (     expression<func<t1, t2, t3, t4, tresult>> expr, t1 arg1, t2 arg2, t3 arg3, t4 arg4) {     return expr.compile ().invoke (arg1, arg2, arg3, arg4); } 

note there's not 1 5 arguments, end binding expression.invoke, takes parameter array of expressions:

public static invocationexpression invoke(expression expression, params expression[] arguments) {     return invoke(expression, (ienumerable<expression>)arguments); } 

luckily, can replicate implementation linqkit calling compile() on expression turn delegate:

public class expressiontester {   public expressiontester()   {     expressions.dosomething.compile().invoke(1, 2, 3, 4, 5);   } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -