I’m trying to create a generic method to retrieve a entity model. So what I’m trying to create a method that have the ability to take an entity model type and return the data of that type.
Here’s what I’ve have so far.
public List<T> Generic<T>(List<T> users) where T : List<T>, new()
{
using (var entities = new TestDBEntities())
{
var enUsers = entities.Users; // How to replace this to make it generic?
return enUsers.ToList();
}
}
Thanks!
Are you using version 4.1 or later (which has DbContext)?
If not, or entities is ObjectContext, you can find the ObjectSet via Reflection, something like this: