独特的在LINQ不工作

独特的在LINQ不工作

本文介绍了独特的在LINQ不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想为以下查询获取不同的EmployeeId.我使用了Distinct,但无法正常使用

Hi
i want to get the distinct EmployeeId for the following query. I used Distinct but its not working

var emp= (from dr in dt.AsEnumerable() orderby dr["EmployeeID"] descending
         select new Employee(){
EmployeeId = int.Parse(dr"EmployeeID"].ToString()),
EmployeeName = dr["EmployeeName"].ToString(),
EmployeeDesignation = dr["EmployeeDesignation"].ToString()
         }).Distinct();

推荐答案


var emp= (from dr in dt.AsEnumerable() orderby dr["EmployeeID"] descending
         select new Employee(){
EmployeeId = int.Parse(dr"EmployeeID"].ToString()),
EmployeeName = dr["EmployeeName"].ToString(),
EmployeeDesignation = dr["EmployeeDesignation"].ToString()
         })Distinct();

成为:

var emp= (from dr in dt.AsEnumerable() orderby dr["EmployeeID"] descending
         select new Employee(){
EmployeeId = int.Parse(dr"EmployeeID"].ToString()),
EmployeeName = dr["EmployeeName"].ToString(),
EmployeeDesignation = dr["EmployeeDesignation"].ToString()
         }).Distinct();


var emp= (from dr in dt.AsEnumerable() orderby dr["EmployeeID"] descending
         select new Employee(){
EmployeeId = int.Parse(dr"EmployeeID"].ToString()),
EmployeeName = dr["EmployeeName"].ToString(),
EmployeeDesignation = dr["EmployeeDesignation"].ToString()
         }).Distinct();


这篇关于独特的在LINQ不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 14:14