Linq Group on Multiple Fields – VB.NET,Anonymous,Key

前端之家收集整理的这篇文章主要介绍了Linq Group on Multiple Fields – VB.NET,Anonymous,Key前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我被困了我需要帮助.我有一个DTO对象与患者地址数据重复.我只需要获得唯一的地址.
Dim PatientAddressDto = New List(Of PatientAddress)

{Populate PatientAddressDto with lots of duplicate data}

PatientAddressDto = (From d In PatientAddressDto
                    Group d By PatientAddressDtoGrouped = New PatientAddress With {
                                                              .Address1 = d.Address1,.Address2 = d.Address2,.City = d.City,.State = d.State,.Zip = d.Zip
                                                              }
                  Into Group
                  Select New PatientAddress With {
                                                  .Address1 = PatientAddressDtoGrouped.Address1,.Address2 = PatientAddressDtoGrouped.Address2,.City = PatientAddressDtoGrouped.City,.State = PatientAddressDtoGrouped.State,.Zip = PatientAddressDtoGrouped.Zip
                                                  }).ToList()

我没有运气尝试过以下内容

PatientAddressDto = (From d In PatientAddressDto
                    Select New PatientAddress With {
                                                  .Address1 = d.Address1,.Zip = d.Zip
                                                    }).Distinct

并且

PatientAddressDto = PatientAddressDto.GroupBy(Function(p) New PatientAddress With {
                                                  .Address1 = p.Address1,.Address2 = p.Address2,.City = p.City,.State = p.State,.Zip = p.Zip
                                                    })
您可以使用 anonymous type并使用 Key keyword,以使相等的行为符合您的期望(C#不需要).

通过指定密钥前缀并删除PatientAddress用法来更改您的分组:

Group d By PatientAddressDtoGrouped = New With {
    Key .Address1 = d.Address1,Key .Address2 = d.Address2,Key .City = d.City,Key .State = d.State,Key .Zip = d.Zip
}
原文链接:https://www.f2er.com/vb/255128.html

猜你在找的VB相关文章