Can you write this method on the DbContext
class?
Then you could write something like in a separate new class file (e.g. ActionContextExtensions.cs
or something like that):
public partial class ActionContext : DbContext
{
public IEnumerable<T> SelectAll<T>() where T: class
{
return this.Set<T>().AsEnumerable();
}
}
This returns the type as defined by the generic parameter – so you can say something like:
var result = db.SelectAll<Employee>()
or
var result = db.SelectAll<Customer>()
or
var result = db.SelectAll<Book>()
1
solved Writing a method which select all the rows and columns of the table given using Entity Framework