Get all rows using entity framework dbset

Wesley Skeen picture Wesley Skeen · Dec 1, 2012 · Viewed 100.1k times · Source

I want to select all rows from a table using the following type of syntax:

public IQueryable<Company> GetCompanies()
{
    return DbContext.Set<Company>()
    .// Select all
}

Forgive me as I am completely new to EF.

Answer

Sergey Berezovskiy picture Sergey Berezovskiy · Dec 1, 2012

Set<T>() is already IQueryable<T> and it returns all rows from table

public IQueryable<Company> GetCompanies()
{
    return DbContext.Set<Company>();    
}

Also generated DbContext will have named properties for each table. Look for DbContext.Companies - it's same as DbContext.Set<Company>()