Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ????

like image 671
Callum Linington Avatar asked Jun 05 '12 15:06

Callum Linington


People also ask

What difference does AsNoTracking () make?

The AsNoTracking() extension method returns a new query and the returned entities will not be cached by the context (DbContext or Object Context). This means that the Entity Framework does not perform any additional processing or storage of the entities that are returned by the query.

What is DbSet in C#?

A DbSet represents the collection of all entities in the context, or that can be queried from the database, of a given type. DbSet objects are created from a DbContext using the DbContext. Set method.

How do I select specific columns in Entity Framework?

We can do that simply by using the “new” operator and selecting the properties from the object that we need. In this case, we only want to retrieve the Id and Title columns. There.


2 Answers

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

_repository.[tablename].ToList();

like image 51
Callum Linington Avatar answered Sep 29 '22 11:09

Callum Linington


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

like image 44
Irf Avatar answered Sep 29 '22 11:09

Irf