Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic LINQ
    primarykey
    data
    text
    <p>I have an XML document defined like so</p> <p><strong>XML File</strong></p> <pre><code>&lt;TABLE&gt; &lt;RECORD&gt; &lt;PAGENUMBER&gt; 1 Of 1&lt;/PAGENUMBER&gt; &lt;OtherFields1&gt;..&lt;/OtherFields1&gt; &lt;OtherFields2&gt;..&lt;/OtherFields2&gt; &lt;/RECORD&gt; &lt;RECORD&gt; &lt;PAGENUMBER&gt; 1 Of 2&lt;/PAGENUMBER&gt; &lt;OtherFields1&gt;..&lt;/OtherFields1&gt; &lt;OtherFields2&gt;..&lt;/OtherFields2&gt; &lt;/RECORD&gt; &lt;RECORD&gt; &lt;PAGENUMBER&gt; 2 Of 2&lt;/PAGENUMBER&gt; &lt;OtherFields1&gt;..&lt;/OtherFields1&gt; &lt;OtherFields2&gt;..&lt;/OtherFields2&gt; &lt;/RECORD&gt; &lt;RECORD&gt; &lt;PAGENUMBER&gt; 1 Of 1&lt;/PAGENUMBER&gt; &lt;OtherFields1&gt;..&lt;/OtherFields1&gt; &lt;OtherFields2&gt;..&lt;/OtherFields2&gt; &lt;/RECORD&gt; &lt;/TABLE&gt; </code></pre> <p>I'm trying to create a dynamic query where i can put a "Fieldname", "Operand", "Value" in a config and LINQ can build a predicate based on it.</p> <p><strong>Config File</strong></p> <pre><code>&lt;CLAUSES&gt; &lt;CLAUSE name="PAGENUMBER" operand="!="&gt;Page 1 Of 1&lt;/CLAUSE&gt; &lt;CLAUSE name="OtherFields1" operand="!="&gt;String.Empty&lt;/CLAUSE&gt; &lt;/CLAUSES&gt; </code></pre> <p>Here is the LINQ i'm using now</p> <p><strong>LINQ Query</strong></p> <pre><code> XDocument jobXML = XDocument.Load(JobFile); List&lt;ClauseObj&gt; clauses = new List&lt;ClauseObj&gt;(); clauses.Add(new ClauseObj { Field = "PAGENUMBER", Operand = "!=", Value = " Page 1 Of 1" }); var q = jobXML.Descendants("RECORD").AsEnumerable(); foreach (var c in clauses) { switch (c.Operand) { case "!=": q = q.Where(r =&gt; r.Element(c.Field).Value != c.Value); break; } } </code></pre> <p>how can i make it read the where clauses "dynamically" and also specify which field names to return?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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