Note that there are some explanatory texts on larger screens.

plurals
  1. POComplex linq filter query required
    primarykey
    data
    text
    <p>I have a class like so:</p> <pre><code>public class LogDataRow { public DateTime TheInterval { get; set; } public ICollection&lt;LogPreviousCurrent&gt; PreviousCurrentItems { get; set; } } </code></pre> <p>which contains a collection of these:</p> <pre><code>public class LogPreviousCurrent : INotifyPropertyChanged { public string Name { get; set; } private decimal? previous; public decimal? Previous { get { return previous; } set { previous = value; PropertyNotification.Notify(this, PropertyChanged, PreviousProperty); } } private const string PreviousProperty = "PreviousProperty"; private decimal? current; public decimal? Current { get { return current; } set { current = value; PropertyNotification.Notify(this, PropertyChanged, CurrentProperty); } } public const string CurrentProperty = "CurrentProperty"; } </code></pre> <p>I use a for loop to create a collection of LogDataRow's that each contain 10 LogPreviousCurrent items. Each LogPreviousCurrent has a Name property.</p> <p>Here is a for loop example:</p> <pre><code> var logDataRows = new List&lt;LogDataRow&gt;(); // loop through for each interval (always 24) for (int i = 1; i &lt;= 24; i++) { // create a new logdatarow and intialise with the interval var dataRow = new logDataRow { Interval = new Interval(customDateObject.TheDate, i) }; // loop thorugh all the types (these equal columns in the destination grid) foreach (var type in customTypes) { // initialise a new preiovuscurrent object var previousCurrent = new LogPreviousCurrent { Name = type.Value.Name }; DetailObject latestDetails = null; DetailObject previousDetails = null; if (latest.Details.ContainsKey(type.Key)) { latestDetails = latest.Details[type.Key]; } if (previous.Details.ContainsKey(type.Key)) { previousDetails = previous.Details[type.Key]; } // get the latest/previous interval value for each details object var latestIntervalValue = latestDetails == null ? null : latestDetails.Details[i]; var previousIntervalValue = previousDetails == null ? null : previousDetails.Details[i]; // if there is a difference in the data if (latestIntervalValue != previousIntervalValue) { previousCurrent.Previous = previousIntervalValue; previousCurrent.Current = latestIntervalValue; } else { // no difference so set both to null previousCurrent.Previous = null; previousCurrent.Current = null; } dataRow.PreviousCurrentItems.Add(previousCurrent); } // only add rows that contain differences if (dataRow.PreviousCurrentItems.Any(a =&gt; a.Previous != a.Current)) { logDataRows.Add(dataRow); } } </code></pre> <p>At the end of this loop I end up with a collection with only rows (dataRow's) that contain LogPreviousCurrent differences.</p> <p>Now what I want to do is the same for columns. i.e. if all LogPreviousCurrent for a particular Name property contain no differences, then those LogPreviousCurrent objects should not exist in the logDataRows collection.</p> <p>So essentially at the end I want to return a colllection that only contains LogPreviousCurrent items with differences between their Previous and Current properties.</p> <p>I have tried doing this using Linq, but with no success to date.</p> <p>I hope this makes sense?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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