How to convert SQL Statement with TOP, COUNT and GROUP BY to return an object list with LINQ

Posted by Junior Mayhé on Stack Overflow See other posts from Stack Overflow or by Junior Mayhé
Published on 2010-05-07T23:18:08Z Indexed on 2010/05/07 23:28 UTC
Read the original article Hit count: 176

Filed under:
|
|
|

Hello guys

does anyone know how to convert this SQL statement to a LINQ to a List?

SELECT TOP(5) COUNT(CategoryId), CategoryName
FROM Tickets 
GROUP BY CategoryName

The result would be something like

public static List<Categories> List()
{
    MyEntities db = new MyEntities();

    /* here it should return a list o Category type */; 
    return db.Category.GroupBy(...).OrderBy(...);

}

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about sql