c# - How to build an IEnumerable<int>.Contains() Expression? -


i'm working asp dynamic data first time , i'm trying build filter. our users have need locate items in list based upon whether or not item child of selected parent (our items can have more 1 parent).

the items in question segments , each segment has property called routeids, of type ienumerable, collection of of segment's parent ids.

i've gotten point in overriding getqueryable method in filter, keep getting exceptions thrown on last line shown:

constantexpression ce = expression.constant(int.parse(this.ddlroutenames.selectedvalue)); parameterexpression pe = expression.parameter(source.elementtype); memberexpression me = expression.property(pe, this.column.name); var callexpression = expression.call(typeof(enumerable), "contains", new type[] { me.type }, ce, me); 

the thought user select appropriate route dropdownlist , i'd check see if segment's routeids property contains route's id.

any pointers on how working?

edit - here exception:

no generic method 'contains' on type 'system.linq.enumerable' compatible supplied type arguments , arguments. no type arguments should provided if method non-generic.

there 2 problems in code:

  1. your parameters backwards. first parameter has collection, second item you're searching for.
  2. your type argument ienumerable<int>, when should int.

so, fixed code is:

var callexpression = expression.call(     typeof(enumerable), "contains", new[] { typeof(int) }, me, ce); 

but seems parts of expression not dynamic, maybe following work too:

expression<func<segment, bool>> expression =     s => s.routeids.contains(int.parse(this.ddlroutenames.selectedvalue)); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -