Let's say I want to find out which eprt_id appears twice. (Which in this case is: 20463)
Eprt_id: 21487 Perceel: Test
subject: Apples
Eprt_id: 21696 Perceel: Test2
subject: Oranges
Eprt_id: 21822 Perceel: Test3
subject: Pears
Eprt_id: 23485 Perceel: Test4
subject: Lemons
Eprt_id: 24238 Perceel: Test55
subject: Watermelons
subject: Oranges
Eprt_id: 20463 Perceel: Test56
subject: Apples
subject: Pears
Eprt_id: 20463 Perceel: Test57
subject: Apples
subject: Pears
This list is obviously a group on Eprt_id and Perceel.
But how can I write a decent linq statement that gives me the result (in this case) 20463 occurs more than once?
I got this list as follows:
var nextGroupedWorklist = from r in SubtractBSNlessFromWerklijst
where r.Eprt_id.HasValue &&
!string.IsNullOrEmpty(r.Subject_id) &&
!string.IsNullOrEmpty(r.Perceel_id) &&
!string.IsNullOrEmpty(r.Hermes_dossier_nr) &&
!string.IsNullOrEmpty(r.Gogis_perceel_nr)
group r by new { r.Eprt_id, r.Gogis_perceel_nr };
I thought a simple count would do. But it obviously returns a count of the elements of the group.
I found a way to get 20463. But is this the best way?
var solution = from r in nextGroupedWorklist
group r by new { r.Key.Eprt_id }
into grp
where grp.Count() > 1
select grp;
Secondly is there a clever way to check if both subjects are the same? (As they are in the example) Both 20463 eprt_id's contain the subject: Apples and Pears. This an example list (as you can see 20463 each has two subjects that are the same in the 2 different Perceel columns) So that would be what I want to check. If they are both the same. I may proceed processing 20463. Otherwise not.:
Eprt_id: 20229 Perceel: WPK02L1072G0 subject: NL.KAD.Persoon.255545276
Eprt_id: 20267 Perceel: WPK02L1051G0 subject: NL.KAD.Persoon.255545276
Eprt_id: 20463 Perceel: ASD31AL2317G0 subject: NL.KAD.Persoon.170412796
Eprt_id: 20463 Perceel: ASD31AL2317G0 subject: NL.KAD.Persoon.455686300
Eprt_id: 20463 Perceel: ASD31AL3076G0 subject: NL.KAD.Persoon.170412796
Eprt_id: 20463 Perceel: ASD31AL3076G0 subject: NL.KAD.Persoon.455686300
Eprt_id: 20524 Perceel: ASD31AL952G0 subject: NL.KAD.Persoon.170348494
Eprt_id: 20524 Perceel: ASD31AL952G0 subject: NL.KAD.Persoon.171028089
Eprt_id: 20939 Perceel: WPK02L260G0 subject: NL.KAD.Persoon.171510661
Eprt_id: 20939 Perceel: WPK02L260G0 subject: NL.KAD.Persoon.171510669
Eprt_id: 20944 Perceel: WPK02L6672G0 subject: NL.KAD.Persoon.171510661
Eprt_id: 20944 Perceel: WPK02L6672G0 subject: NL.KAD.Persoon.171510669
Eprt_id: 21487 Perceel: WPK02L2503G0 subject: NL.KAD.Persoon.170459916
Eprt_id: 21696 Perceel: ASD02A7343A61 subject: NL.KAD.Persoon.171440573
Eprt_id: 21822 Perceel: WPK02L1602G0 subject: NL.KAD.Persoon.459669099