我被困了我需要帮助.我有一个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 }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。