开发者

finding distinct rows in dataset using linq

开发者 https://www.devze.com 2023-03-25 14:26 出处:网络
I am using the below query to find the distinct rows from a dataset but its not getting me the distinct for example its not removing the duplicate and show me the distinct count.

I am using the below query to find the distinct rows from a dataset but its not getting me the distinct for example its not removing the duplicate and show me the distinct count.

var distinctRows 开发者_Go百科= (from DataRow dRow in _dsMechanic.Tables[0].Rows
                                select new { col1 = dRow["colName"] }).Distinct();


This should work:

var distinctRows = (
    from DataRow dRow in _dsMechanic.Tables[0].Rows
    select dRow["colName"]).
    Distinct();

Doing the distinct on an anonymous type is just asking for trouble.

0

精彩评论

暂无评论...
验证码 换一张
取 消