开发者

finding distinct rows in dataset using linq

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜