c# - nested "Any" in is not working in dynamic linq -
we offer our users ability build own queries on data. make work use dynamic linq library. construct giving problems: have collection of persons query follows:
( dossieritems.any( dossierfiles.any())) && ( firstname.contains( \"h\" ) ) this results in error stating that:
no property or field 'firstname' exists in type 'dossieritem'
which entirely correct: firstname property of person. closing parenthesis after second “any” somehow missed.
( firstname.contains( \"h\" ) ) && ( dossieritems.any( dossierfiles.any() ) ) the statement above works fine, can’t control order in predicates entered.
is there way in modify nested parts play nice following predicates?
this stack trace produced dynamic linq when parsing dynamic linq string:
@ system.linq.dynamic.expressionparser.parsememberaccess(type type, expression instance) @ system.linq.dynamic.expressionparser.parseidentifier() @ system.linq.dynamic.expressionparser.parseprimarystart() @ system.linq.dynamic.expressionparser.parseprimary() @ system.linq.dynamic.expressionparser.parseunary() @ system.linq.dynamic.expressionparser.parsemultiplicative() @ system.linq.dynamic.expressionparser.parseadditive() @ system.linq.dynamic.expressionparser.parsecomparison() @ system.linq.dynamic.expressionparser.parselogicaland() @ system.linq.dynamic.expressionparser.parselogicalor() @ system.linq.dynamic.expressionparser.parseexpression() @ system.linq.dynamic.expressionparser.parseparenexpression() @ system.linq.dynamic.expressionparser.parseprimarystart() @ system.linq.dynamic.expressionparser.parseprimary() @ system.linq.dynamic.expressionparser.parseunary() @ system.linq.dynamic.expressionparser.parsemultiplicative() @ system.linq.dynamic.expressionparser.parseadditive() @ system.linq.dynamic.expressionparser.parsecomparison() @ system.linq.dynamic.expressionparser.parselogicaland() @ system.linq.dynamic.expressionparser.parselogicalor() @ system.linq.dynamic.expressionparser.parseexpression() @ system.linq.dynamic.expressionparser.parse(type resulttype) @ system.linq.dynamic.dynamicexpression.parselambda(parameterexpression[] parameters, type resulttype, string expression, object[] values) @ system.linq.dynamic.dynamicexpression.parselambda(type ittype, type resulttype, string expression, object[] values) @ system.linq.dynamic.dynamicqueryable.where(iqueryable source, string predicate, object[] values) @ repositories.base.repository`1.applyquery(iqueryable`1 entities, guid queryid) @ search.searchqueryresult.runquery[t](iqueryable`1 entities, irepository`1 repository) code sample repro
using microsoft.visualstudio.testtools.unittesting; using system.collections.generic; using system.linq.dynamic; namespace classlibrary1 {
[testclass] public class unittest1 { [testmethod] public void testmethod1() { // arrange var allas = new list<a>(); // act // pass var actual = allas.where("(name = \"\")&&(bs.any(cs.any()))"); // fail var actual = allas.where("(bs.any(cs.any()))&&(name = \"\")"); } } public class { public string name { get; set; } public ilist<b> bs { { return bs; } set { bs = value; } } private ilist<b> bs = new list<b>(0); } public class b { public a { get; set; } public ilist<c> cs { { return cs; } set { cs = value; } } private ilist<c> cs = new list<c>(0); } public class c { public b b { get; set; } } }
if it's of anyone, figured out cause. issue in original source , have done pull request on github fix it.
https://github.com/kahanu/system.linq.dynamic/pull/68
this issue occur nested linq method call. solved replacing variable in parser stack right type popped when stepping out of method call.
Comments
Post a Comment