Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This query seems to be correct from point of view of result obtained.</p> <p>But in your inner query <code>tis.Where(p =&gt; p.PlanProgress != null &amp;&amp; p.PlanProgress &gt; 0).Max(w =&gt; w.EndDate)</code> is computed for each element in collection with <code>t.PlanProgress &gt; 0</code></p> <p>So its a better way to obtain Max value outside of a query as follows:</p> <pre><code>var max = tis.Where(p =&gt; p.PlanProgress != null &amp;&amp; p.PlanProgress &gt; 0).Max(w =&gt; w.EndDate); tis.First( t =&gt; t.PlanProgress &gt; 0 &amp;&amp; t.EndDate == max); </code></pre> <p>Going further p.PlanProgress != null is allways true since p.PlanProgress is not of Nullable type. So our code becomes like this:</p> <pre><code>var max = tis.Where(p =&gt; p.PlanProgress &gt; 0).Max(w =&gt; w.EndDate); tis.First( t =&gt; t.PlanProgress &gt; 0 &amp;&amp; t.EndDate == max); </code></pre> <p>Or you can change a definition of your class and make p.PlanProgress of Nullable type:</p> <pre><code>public class TaskWeekUI { public Guid TaskWeekId { get; set; } public Guid TaskId { get; set; } public Guid WeekId { get; set; } public DateTime EndDate { get; set; } public string PersianEndDate { get; set; } public double? PlanProgress { get; set; } public double ActualProgress { get; set; } } var max = tis.Where(p =&gt; p.PlanProgress.HasValue &amp;&amp; p.PlanProgress.Value &gt; 0).Max(w =&gt; w.EndDate); tis.First( t =&gt; t.PlanProgress.HasValue &amp;&amp; t.PlanProgress.Value &gt; 0 &amp;&amp; t.EndDate == max); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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