ADO.NET Entity Framework : Paging EntitySQL

Paging in EntitySQL is really easy to achieve. You have got two important sub-clauses (or query operators) are available, SKIP and LIMIT.

So your paging EntitySQL query would ideally look like,

"SELECT VALUE e FROM NorthwindEntities.Customers AS e ORDER BY e.CompanyName SKIP 10 LIMIT 10 ";

The most important part is that you *must* implement ORDER BY clause for SKIP and LIMIT.

using (EntityConnection conn =

    new EntityConnection("name=NorthwindEntities"))

{

    conn.Open();

    //EntitySQL

    string sQueryString = "SELECT VALUE e FROM NorthwindEntities.Customers AS e ORDER BY e.CompanyName SKIP 10 LIMIT 10 ";

    using (EntityCommand comm =

        new EntityCommand(sQueryString,conn))

    {

        EntityDataReader reader =

            comm.ExecuteReader(CommandBehavior.SequentialAccess);

        while (reader.Read())

        {

            Console.WriteLine(reader["CompanyName"]);

        }

    }

}

PS. You need to make CommandBehavior.SequentialAccess for EntityDataReader.

Namoskar!!!