7
Answers

group a table by a column which has select distinct on colmn

diamond diamond

diamond diamond

11y
1.7k
1
Hi ,

I have a table with some fields, it is not easy to describe my issue but, I want to group table by a src field which is have select distinct on dst field.

Table name is F has src, name, dst, time fields.

I want my query by linq is resulted as below:


src      dst                         src                dst
1          a
1           c                           1                  a,c
1           a        ====>>      2                  b
2           b                            3                   c
3           c

I want for every src the dst are put in list.

this code gives an error.

List<string> srcaddress = (from DataRow dr in dt.Rows  group dr by dr["dst"].ToString() Select new dr["src"]).ToList();
Answers (7)