Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic where clause in LINQ to Objects
    text
    copied!<p>I know there are a lot of examples of this on the web, but I can't seem to get this to work.</p> <p>Let me try to set this up, I have a list of custom objects that I need to have limited on a range of values. </p> <p>I have a sort variable that changes based on some action on the UI, and I need to process the object differently based on that.</p> <p>Here is my object:</p> <pre><code>MyObject.ID - Just an identifier MyObject.Cost - The cost of the object. MyObject.Name - The name of the object. </code></pre> <p>Now I need to filter this based on a range in the cost, so I will have something similar to this, considering that I could be limiting by Either of my bottom two properties.</p> <pre><code>var product = from mo in myobject where mo.Cost &lt;= 10000 </code></pre> <p>or</p> <pre><code>var product = from mo in myobject where mo.Name equals strName </code></pre> <p>Now I have the dynamic linq in my project, but I'm not figuring out how to get it to actually work, as when I do some of the examples I am only getting:</p> <pre><code>Func&lt;Tsourse&gt;bool&gt; predicate </code></pre> <p>as an option.</p> <p><strong>Update:</strong> I am trying to find a solution that helps me Objectify my code, as right now it is a lot of copy and paste for my linq queries.</p> <p><strong>Update 2:</strong> Is there an obvious performance difference between:<br /></p> <pre><code>var product = from mo in myobject ... a few joins ... where mo.Cost &lt;= 10000 </code></pre> <p>and</p> <pre><code>var product = (from mo in myobject ... a few joins ...) .AsQueryable() .Where("Cost &gt; 1000") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload