LINQ Distinct not work [Resolved]

Posted by Naraayanan under C# on 12/26/2012 | Points: 10 | Views : 7069 | Status : [Member] | Replies : 2
Hi All,

  List<ClsEmployees> objEmployee = new List<ClsEmployees>
{
new ClsEmployees { EmpID = "1001" ,Name ="GANTEC", Salary =10000 },
new ClsEmployees { EmpID = "1002" ,Name ="IBM", Salary =15000 },
new ClsEmployees { EmpID = "1003" ,Name ="CTS", Salary =20000 },
new ClsEmployees { EmpID = "1004" ,Name ="WIPRO", Salary =30000 },
new ClsEmployees { EmpID = "1005" ,Name ="SATHYAM", Salary =40000 },
new ClsEmployees { EmpID = "1006" ,Name ="BUTTERFLY", Salary =50000 },
new ClsEmployees { EmpID = "1007" ,Name ="CON", Salary =10000 },
new ClsEmployees { EmpID = "1008" ,Name ="TVS", Salary =75000 },
new ClsEmployees { EmpID = "1008" ,Name ="TVS", Salary =75000 },
new ClsEmployees { EmpID = "1010" ,Name ="TATA", Salary =90000 },
new ClsEmployees { EmpID = "1009" ,Name ="GANTEC COR", Salary =100000 },
new ClsEmployees { EmpID = "1009" ,Name ="GANTEC COR", Salary =100000 },
};


Query for Distinct:
var dis = (from emp in objEmployee select emp).Distinct();
dataGridView1.DataSource = dis.ToList();


It doesn't work .Why?

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Ranjeet_8 on: 12/26/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
Try ths,
Query for Distinct:
 var dis = (from emp in objEmployee select new { emp.EmpID,emp.Name,emp.Salary }).Distinct(); 


Please Mark As Answer if this helps you

.

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 12/26/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Thanks

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response