Linq Distinct() by name for populate a dropdown list with name and value

Posted by AndreMiranda on Stack Overflow See other posts from Stack Overflow or by AndreMiranda
Published on 2009-05-26T19:08:50Z Indexed on 2012/03/29 17:29 UTC
Read the original article Hit count: 236

Filed under:
|
|

I'm trying to populate a Drop down list with pharmaceutical companies, like Bayer, Medley etc. And, I'm getting theses names from DB and theses names are repeated in DB, but with different id's.

I'm trying to use Linq Distinct(), but I don't want to use the equality comparer. Is there another way?

My drop down list must be filled with the id and the name of the company.

I'm trying something like:

var x = _partnerService
           .SelectPartners()
           .Select(c => new {codPartner = c.codPartner, name = c.name})
           .Distinct();

This is showing repeated companies in ddl.

thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql