Linq Esempi

Caricare un dictionary di liste usando direttamente linq

[code lang=”vb”]

Function addToDic(dic As Dictionary(Of Integer, List(Of Integer)), chiave As Integer, valore As Integer) As Integer
If dic.ContainsKey(chiave) Then
dic(chiave).Add(valore)
Else
Dim li As New List(Of Integer)
li.Add(valore)
dic.Add(chiave, li)
End If
Return 1
End Function

[/code]

[code lang=”vb”]

Dim dic As New Dictionary(Of Integer, List(Of Integer))
Dim tot = (From r In insieme Select addToDic(dic, CInt(r.campochiave), CInt(r.campovalore))).Count

[/code]

Costruzione di una struttura complessa a partire da una relazione db complessa, implementata con fk su db:
Utenti ->(a molti) -> Azioni -> (a uno) -> TipoAzioni
(tipi anonimi/entity framework)

[code lang=”vb”]

Dim Query = (From r In UTENTI Select New With {r.ID, r.DATA_UTENTE, r.NOME, r.COGNOME, Key .azi = r.AZIONI.Select(Function(k) New With {k.ID_AZIONE, k.DATA_AZIONE, k.TIPO_AZIONE.NOME_TIPO})}).ToList

[/code]

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *