Reputation: 1327
I have this linq query where i want to remove all the duplicates based on the column MAILADR (but keep the other columns):
Dim dataObject = (From a In db.TABLE1 Select New With {
.ID = a.BENUTZERNR,
.MAILADR = a.EMAIL,
.BENUTZERGRP = a.USRGRP
}) _
.Union(
(From b In db.TABLE12 Select New With {
.ID = b.ID,
.MAILADR = b.MAILADR,
.BENUTZERGRP = b.BENUTZERGRP
}) _
)
Upvotes: 1
Views: 809
Reputation: 1327
I ended up using the GroupBy
operator:
dataObject = dataObject.GroupBy(Function(c) c.MAILADR).Select(Function(group) group.First())
Upvotes: 0
Reputation: 6692
You can provide a comparison method (IEqualityComparer) on the overloaded Union method.
http://msdn.microsoft.com/en-us/library/bb358407.aspx
Upvotes: 3