Newbie to LINQ, and trying to write the following query...
select
f.Section_ID,
f.Page_ID,
f.SortOrder,
f.Type
from
(
select
Section_ID,
min(SortOrder) as minSortOrder
from
ContentPages
group by
Section_ID
) as x
inner join
ContentPages as f on
f.Section_ID = x.Section_ID and
f.SortOrder = x.minSortOrder;
Notes:
- 'Section' has many 'ContentPages'
- Sections are ordered by a 'SortOrder' field
- ContentPages are also ordered by a 'SortOrder' field
Table: Section
Section_ID....Name.......SortOrder
....1.........One..........1......
....2.........Two..........3......
....3.........Three........2......
Table: ContentPage
Page_ID.......Section_ID.......Title..............SortOrder
....11.............1.......... Page One.............1......
....12.............1...........Page Two.............3......
....13.............2...........Page Three...........2......
....16.............2.......... Page Four............4......
....17.............2...........Page Eight...........5......
....18.............1...........Page Ten.............6......
The above query could possibly be written another way, so here's what I'm trying to do:
- I need to return a list of the first ContentPage within each Section (when sorted by ContentPage.SortOrder)
- Sort results by Section.SortOrder
- Show Section.Name (join on Section_ID?) in the result as well
Last 2 points are not covered by the sql query above and are more of a 'nice to have'...
Desired Result
Page_ID.......Section_ID...SectionName.....Title..............SortOrder
....11.............1.........One......... Page One.............1......
....13.............2.........Two..........Page Three...........2......
Any help is appreciated. Thanks!