C# LINQ Statement for the Below Scenario -


i trying build linq statement joining below 2 list in c#.

list1:

formid  formround 2        1 2        2 2        3 3        1 4        2 

list2:

formid  formround   category    date 2           1        test1     23-aug 2           1        test2     24-aug 2           1        test3     25-aug 2           2        test1     26-aug 2           2        test3     27-aug 3           1        test1     28-aug 3           1        test2     29-aug 3           1        test3     30-aug 

i should output below.

formid  formround   test1date   test2date   test3date 2          1          23-aug    24-aug       test3 2          2          26-aug    na           27-aug 3          3          28-aug    29-aug       na 

can please me in framing linq statement?

this linq query might like:

var results = (from in list1                join b in list2 on new { a.formid, a.formround } equals new { b.formid, b.formround }                group b new { a.formid, a.formround } c                select new                 {                    c.key.formid,                    c.key.formround,                    test1date = c.where(d => d.category == "test1").select(e => e.date).firstordefault(),                    test2date = c.where(d => d.category == "test2").select(e => e.date).firstordefault(),                    test3date = c.where(d => d.category == "test3").select(e => e.date).firstordefault(),                }); 

which, using sample data, produces:

2   1   23-aug  24-aug  25-aug 2   2   26-aug  null    27-aug 3   1   28-aug  29-aug  30-aug 

this not expected results, think have issues you're expecting based on comments on question.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -