Hello,
I have a db table and I want to use Linq to map the db fields to a list of objects. Here is my Class definition.
Public Class CalendarMonth
Public Property Run_Name As String
Public Property Month_Scope As List(Of MonthScope)
End Class
and my MonthScope class looks like this:
Public Class MonthScope
Public Property h_yyyy As Integer?
Public Property h_mm As Integer?
Public Property h_mon As String
End Class
I want to Query the below table so that I get the below:
2019-1
2019 1 Jan
2019 2 Feb
2019 3 Mar
2019 4 Apr
2019-2
2019 5 May
2019 6 Jun
2019 7 Jul
2019 8 Aug
2019-3
2019 9 Sep
2019 10 Oct
2019 11 Nov
2019 12 Dec
Below is my data set
RUN_NAME H_YYYY H_MM H_MON
2019-1 2019 1 Jan
2019-1 2019 2 Feb
2019-1 2019 3 Mar
2019-1 2019 4 Apr
2019-2 2019 5 May
2019-2 2019 6 Jun
2019-2 2019 7 Jul
2019-2 2019 8 Aug
2019-3 2019 9 Sep
2019-3 2019 10 Oct
2019-3 2019 11 Nov
2019-3 2019 12 Dec
What I have tried:
CalendarMonthList = (From rw As DataRow In dt.Rows Select New CalendarMonth With {
.Run_Name = rw("run_name").ToString, .Month_Scope = (From rw1 As DataRow In dt.Rows Where rw1("run_name") = .Run_Name Select New MonthScope With {.h_yyyy = rw1("h_yyyy"), .h_mm = rw1("h_mm"), .h_mon = rw1("h_mon")}).Distinct.ToList()}).Distinct.ToList()