使用Linq返回不同的对象

时间:2019-03-26 12:40:38

标签: vb.net linq class

(我是VB.Net的新手)我有以下三个类:

Public Class Classe_PIVA_Cond

Public Property my_codFiscale As String
Public Property my_presenzaDuplicati As Boolean
Public Property my_listaCondominii As New List(Of Classe_Condominio)

Public Sub New()
End Sub


Public Sub New(codFiscale As String, presenzaDuplicati As Boolean, listaCondominii As List(Of Classe_Condominio))
    Me.my_codFiscale = codFiscale
    Me.my_presenzaDuplicati = presenzaDuplicati
    Me.my_listaCondominii = listaCondominii
End Sub

End Class

'=================================

Public Class Classe_Condominio

Public Property my_Studio As New Classe_Studio
Public Property my_Amministratore As New Classe_Amministratore
Public Property my_codCondominio As String
Public Property my_indirizzo As String
Public Property my_comune As String
Public Property my_cap As String
Public Property my_provincia As String
Public Property my_codFiscale As String

Public Sub New()
End Sub

Public Sub New(studio As Classe_Studio, amministratore As Classe_Amministratore, codCondominio As String, indirizzo As String, comune As String, cap As String, provincia As String, codFiscale As String)
    Me.my_Studio = studio
    Me.my_Amministratore = amministratore
    Me.my_codCondominio = codCondominio
    Me.my_indirizzo = indirizzo
    Me.my_comune = comune
    Me.my_cap = cap
    Me.my_provincia = provincia
    Me.my_codFiscale = codFiscale
End Sub

End Class

'=================================

Public Class Classe_Studio

Public Property my_codice As String
Public Property my_ragioneSociale As String
Public Property my_pIvaCodFisc As String

Public Sub New()
End Sub

Public Sub New(codice As String, ragioneSociale As String, pIvaCodFisc As String)
    Me.my_codice = codice
    Me.my_ragioneSociale = ragioneSociale
    Me.my_pIvaCodFisc = pIvaCodFisc
End Sub

End Clas

我会尝试在List(Of Classe_PIVA_Cond)的列表中返回不同Classe_Studio.my_codice的列表。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

尝试

    Dim my_codiceDistinctList = Classe_PIVA_CondList
                                        .SelectMany(Function(x) x.my_listaCondominii)
                                        .Select(Function(y) y.my_Studio.my_codice)
                                        .Distinct()
                                        .ToList()