alirezanet/Gridify

Compare elements nested in a list of the root object

alirezanet opened this issue · 0 comments

Discussed in #153

Originally posted by Robotxm February 21, 2024
Hello, I have following object definitions:

public record Item(string Name, List<TimeSchedule> Schedules);

public record TimeSchedule(int Start, int End);

Now I want to find all Items who has a schedule that its End time is before Start time.

With native LINQ I can do this:

List<Item> items =
[
    new Item("Item1", [new TimeSchedule(1, 2), new TimeSchedule(2, 3)]),
    new Item("Item2", [new TimeSchedule(1, 4), new TimeSchedule(4, 3)]),
    new Item("Item3", [new TimeSchedule(3, 2), new TimeSchedule(2, 3)]),
];

var results = items.Where(x => x.Schedules.Any(s => s.End < s.Start));

So how can I achieve this using Gridify?