converting a SQL statement to LINQ query on a DataTable

987 Views Asked by At

I am studying that Linq to DataTable,Lambda. Because is difficult want to change sql to linq,Lambda, is not doing.

Below the SQL code is member list that remove telephone number repetition. I will thank if help.

SELECT A.no, B.name, B.userId, B.homeTel2    
FROM

    (  SELECT homeTel2, min(no) NO
       FROM  OF_Member
       GROUP BY homeTel2 
    ) A
    INNER JOIN OF_Member B
        ON A.NO = B.NO

Progressing work ============

var objectName =from t in mMemberTable.AsEnumerable()
group t by t.Field("homeTel2")

2

There are 2 best solutions below

2
On

Try this link:

Linq to Entities simple group query

converting ms sql “group by” query to linq to sql

                var objectName =from t in mMemberTable.AsEnumerable()
                group t by t.Field<string>("homeTel2") into groups
                select groups;

Hope this helps,

Regards

1
On

Try using a tool called LINQ Pad. This is the best tool so far for writing and testing sql/LINQ queries and moreover it is free. It also allows you to convert your queries from LINQ to SQL and vice-versa.

http://www.linqpad.net