Select All Rows Using Entity Framework

I'm trying to select all the rows out of a database using entity framework for manipulation before they're sent to the form

var ptx = [modelname].[tablename]();
ptx.[tablename].Select(????)

what goes in the ????


Solution 1:

I used the entitydatasource and it provide everything I needed for what I wanted to do.

_repository.[tablename].ToList();

Solution 2:

Entity Framework has one beautiful thing for it, like :

var users = context.Users; 

This will select all rows in Table User, then you can use your .ToList() etc.


For newbies to Entity Framework, it is like :

PortalEntities context = new PortalEntities();
var users = context.Users;

This will select all rows in Table User

Solution 3:

How about:

using (ModelName context = new ModelName())
{
    var ptx = (from r in context.TableName select r);
}

ModelName is the class auto-generated by the designer, which inherits from ObjectContext.

Solution 4:

You can use this code to select all rows :

C# :

var allStudents = [modelname].[tablename].Select(x => x).ToList();