Search code examples
linq2sxc

2sxc - Get Calendar data


I have Entity "News" with many fields and entity "EventTime" which contains field "DateTime"

In "News" there is also field for List of "EventTime"

I am able to filter and sort "News" on many fields of "News" entity...

var data = AsDynamic(App.Data["News"]);
data = data.Where(x => ....);
data = data.OrderBy(x => ...);

But I don't know how to make linq query to get list of "News" for all "EventTime"..

eg.: if I have this data:

News[0]-Title1 with EventTime[0]-2019/05/01 and EventTime[1]-2019/06/02
News[1]-Title2 with EventTime[0]-2019/05/10 and EventTime[1]-2019/06/10

I want to get list of "News" like this:

Title1 - 2019/05/01
Title2 - 2019/05/10
Title1 - 2019/06/02
Title2 - 2019/06/10

How to get this?


Solution

  • This seems to mostly be a LINQ question, basically you want to have a result where the original items occur more than once, and the final sort uses multiple possible values. I recommend to something along these lines:

    1. create a list of all items with their new date, do this using Linq SelectMany and in that, do an newsItem.Select return something like a new { Date = the-date-you-need, Item = the-as-dynamic }.
    2. Now OrderBy the Date

    That's basically it :)