【发布时间】:2012-04-24 21:16:21
【问题描述】:
我被难住了。我需要帮助。我有一个带有重复患者地址数据的 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
})
【问题讨论】:
-
你的评论是对的,我会删除我的答案,因为它没有帮助。
-
您是否尝试过只选择要检查的字段,然后在结果上使用 .Distinct()?
-
米奇,是的,我有。我在上面编辑了我的评论以包含一些替代方案。
标签: vb.net linq linq-to-objects