Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linq getting selections using ToList not working

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have a collection of a class (List<EditGrid>). I am trying to find duplicates and found this online and it seemed pretty clean but I am getting an error:

Cannot convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<OrderManagement.EntityLayer.EditGrid>'

I tried this a couple of ways and got the same error.

Code:
List<EditGrid> duplicates = Selections.GroupBy(x => x.KTrace)
                             .Where(g => g.Count() > 1)
                             .Select(g => g.Key)
                             .ToList();
or

List<EditGrid> duplicates = (List<EditGrid>)Selections.GroupBy(x => x.KTrace)
                             .Where(g => g.Count() > 1)
                             .Select(g => g.Key)
                             .ToList();

Where is my generic List of string?

How can I get this to work?

Thanks,

Tom
 
Remove the .Select line. You are basically telling the linq to select only the key, rather than the entire object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top