Linq Group on Multiple Fields – VB.NET,Anonymous,Key
发布时间:2020-12-17 00:28:28 所属栏目:大数据 来源:网络整理
导读:我被困了我需要帮助.我有一个DTO对象与患者地址数据重复.我只需要获得唯一的地址. Dim PatientAddressDto = New List(Of PatientAddress){Populate PatientAddressDto with lots of duplicate data}PatientAddressDto = (From d In PatientAddressDto Group
我被困了我需要帮助.我有一个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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |