Help on Dinstinct - Linq

  • Thread starter Thread starter BlackSun
  • Start date Start date
B

BlackSun

Hi,
I wrote this code:

Private Function Carica() As IEnumerable(Of GCA)
Return From lista In DatiBase _
Where lista.Field(Of String)(Colonna3) <> "" _
Order By lista.Field(Of String)
(Colonna2),lista.Field(Of String)(Colonna3) _
Select New GCA With {.AAAA= lista.Field(Of String)
(Colonna1), _
.BBBB= lista.Field
(Of String)(Colonna2), _
.CCCC= lista.Field
(Of String)(Colonna3) _
}
End Function
It works fine but.... how can I change to get the list with distinct
rows for Colonna3
(= GCA.CCCC)?

Thanks in advance!
Cheers,
BlackSun
 
BlackSun said:
Private Function Carica() As IEnumerable(Of GCA)
Return From lista In DatiBase _
Where lista.Field(Of String)(Colonna3) <> "" _
Order By lista.Field(Of String)
(Colonna2),lista.Field(Of String)(Colonna3) _

Group By CCCC = lista.Field(Of String)(Colonna3)
Into Group _
Select New GCA With {.AAAA= Group.First().Field(Of String)
(Colonna1), _
.BBBB= Group.First().Field
(Of String)(Colonna2), _
.CCCC= Group.CCCC _
}
End Function
It works fine but.... how can I change to get the list with distinct
rows for Colonna3
(= GCA.CCCC)?

See the changes I made above. But that is pseudo code to suggest how to
approach that, not tested code. You might need to post the exact
definitions of your types like DatiBase if you can't get it to work.
 
Hi,

thank you for you help!

Cheers,
BlackSun

                       Group By CCCC = lista.Field(Of String)(Colonna3)
Into Group _


See the changes I made above. But that is pseudo code to suggest how to
approach that, not tested code. You might need to post the exact
definitions of your types like DatiBase if you can't get it to work.
 
Hi,
                       Group By CCCC = lista.Field(Of String)(Colonna3)
Into Group _


See the changes I made above. But that is pseudo code to suggest how to
approach that, not tested code. You might need to post the exact
definitions of your types like DatiBase if you can't get it to work.

Thak you for your reply... I changed the code and now it works but I
have another question....
If I would like to have distinct rows not for Column3 but for Column2
and Column3 togheter?

Ex:

Column 2 | Column3
AAA | A1A1 => OK
AAA | BBB => OK
AAA | CCCC => OK
AAA | BBB => NO
ADES | A1A1 => OK

Thak you in advance.

Cheers,
BlackSun
 
BlackSun said:
Thak you for your reply... I changed the code and now it works but I
have another question....
If I would like to have distinct rows not for Column3 but for Column2
and Column3 togheter?

You can have composite grouping keys so simply use e.g.
Group By CCCC = lista.Field(Of String)(Column3), DDDD =
lista.Field(Of String)(Column2) Into Group
 
Hi,
You can have composite grouping keys so simply use e.g.
   Group By CCCC = lista.Field(Of String)(Column3), DDDD =
lista.Field(Of String)(Column2) Into Group

Thank you very much for your help and sorry for the late in answering!

Cheers,
BlackSun
 
Back
Top