Tôi đang bối rối. Tôi cần giúp đỡ. Tôi có một đối tượng DTO với dữ liệu địa chỉ bệnh nhân trùng lặp. Tôi cần chỉ nhận được các địa chỉ duy nhất.Linq Group trên nhiều lĩnh vực - VB.NET, Anonymous, Key
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()
Tôi đã thử những điều sau đây không có may mắn:
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
và cũng
PatientAddressDto = PatientAddressDto.GroupBy(Function(p) New PatientAddress With {
.Address1 = p.Address1,
.Address2 = p.Address2,
.City = p.City,
.State = p.State,
.Zip = p.Zip
})
Bạn đã đúng với nhận xét của mình, tôi sẽ xóa câu trả lời vì nó không hữu ích. – daniloquio
Bạn đã thử chỉ chọn các trường bạn muốn kiểm tra, sau đó sử dụng .Distinct() trên kết quả? –
Mikey, vâng tôi có. Tôi đã chỉnh sửa bình luận của mình ở trên để bao gồm một số lựa chọn thay thế. – wavedrop