Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just do something like this</p> <pre><code>from s in ServicosFinanceiro where (s.ParcelaAtual == 1 &amp;&amp; s.DataVencto1 &gt;= start &amp;&amp; s.DataVencto1 &lt;= end) || (s.ParcelaAtual == 2 &amp;&amp; s.DataVencto2 &gt;= start &amp;&amp; s.DataVencto2 &lt;= end) || (s.ParcelaAtual == 3 &amp;&amp; s.DataVencto3 &gt;= start &amp;&amp; s.DataVencto3 &lt;= end) || (s.ParcelaAtual == 4 &amp;&amp; s.DataVencto4 &gt;= start &amp;&amp; s.DataVencto4 &lt;= end) select s </code></pre> <p>That's similar to what I would do using plain T-SQL.</p> <p>Observe that <code>start</code> and <code>end</code> are plain C# variables, representing the date period you need to query against.</p> <p>This is probably better than generating a SQL <code>CASE</code> statement on the where clause (which should also be possible).</p> <p>Of course, <a href="https://stackoverflow.com/questions/2161573/how-to-optimize-the-use-of-the-or-clause-when-used-with-parameters-sql-server"><code>OR</code> statements are not really recommended, perfomance-wise</a>. If this is a concern, you should just make 4 LINQ statements and combine their results.</p> <p><strong>Edit</strong> Since you don't seem to be convinced, let me give you another option:</p> <pre><code>( from s in ServicosFinanceiro where (s.ParcelaAtual == 1 &amp;&amp; s.DataVencto1 &gt;= start &amp;&amp; s.DataVencto1 &lt;= end) select s ).Union( from s in ServicosFinanceiro where (s.ParcelaAtual == 2 &amp;&amp; s.DataVencto2 &gt;= start &amp;&amp; s.DataVencto2 &lt;= end) select s ).Union( from s in ServicosFinanceiro where (s.ParcelaAtual == 3 &amp;&amp; s.DataVencto3 &gt;= start &amp;&amp; s.DataVencto3 &lt;= end) select s ).Union( from s in ServicosFinanceiro where (s.ParcelaAtual == 4 &amp;&amp; s.DataVencto4 &gt;= start &amp;&amp; s.DataVencto4 &lt;= end) select s ) </code></pre> <p>This will generate a single <code>UNION</code> statement, composed of 4 subqueries. This is similar to what I said about combining 4 Linq queries - but we are doing that on the database server this way (and indexes over the <code>DataVencto1</code> .. <code>DataVencto2</code> will be considered by the SQL Server optimizer). </p>
 

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