gpt4 book ai didi

vb.net - Linq多个字段组-VB.NET,匿名, key

转载 作者:行者123 更新时间:2023-12-03 14:40:20 24 4
gpt4 key购买 nike

我很沮丧我需要帮助。我有一个重复的患者地址数据的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,
.Address2 = d.Address2,
.City = d.City,
.State = d.State,
.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#不需要)。

通过指定Key前缀来更改分组,并删除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
}

关于vb.net - Linq多个字段组-VB.NET,匿名, key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9997001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com