c# - Scope of Collections used in LINQ Predicates -


I really like it allows me to make all kinds of queries very dynamically. Vector variables can be passed around different objects and they can combine it with those values, which they know about, etc. Since then when I need to use one A hashed collection Bzzt! Crash and burn

For example (example / pseudo-code, this may or may not be compiled / run):

  Safe expression & lt; Funk & lt; MyClass, bool & gt; & Gt; GetWherePredicate () {string [] selectedValues ​​= Request.Form.GetValues ​​("Checkbox 1") ?? New string [0]; HashSet & LT; Integer & gt; SelectIDs = New Hashet & lt; Int & gt; (Selected values.Cast & lt; int & gt; ()); Expression & lt; Func & lt; MyClass, bool & gt; & Gt; Predicate = PredicateBuilder.True & lt; MyClass & gt; (); Predicate = predicate.And (s = & gt; Selected ID. Insertion (s.ID)); Prediction of return; } Recover secure void () {expression & lt; Funk & lt; MyClass, bool & gt; & Gt; Predicate = GetWherePredicate (); IEnumerable & LT; MyClass & gt; Recovered value = MyDataContext.GetTable & lt; MyClass & gt; Where (estimated); }  

When I try to do this, I get an NotSupportedException: in the selected embedded SQL method of 'Boolean Containers (Ints 32)' The selected ID is not in the area due to the HashSet, if I do all this in the same method, then it works fine.

I need to know correctly in order to solve my predictions or compile it or whatever it can be used in a different radius from where the hashaseet is declared, any help ?

UPDATE: I did it very wrong that the code below works fine, so there is no scope thanks J.

  string [] selectedValues ​​= Request.Form.GetValues ​​("checkbox 1") ?? New string [0]; Expression & lt; Func & lt; MyClass, bool & gt; & Gt; Predicate = PredicateBuilder.True & lt; MyClass & gt; (); Predicate = predicate.And (s = & gt; Selected Values. Provisioning (s.ID.ToString ()); Exception which you quote, it seems that this radius is a factor.  

/ P>

My answer is that you have selectedIDs to the IEnumerable & lt; Int & gt; instead of HashSet & lt; Int & gt; needs to be declared as (or just enter it before joining it), but it does not account for working for everyone in the same method, so I Uncertainty.

Any real code that is displaying this behavior will be difficult to troubleshoot any further problems.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -