jeudi 7 juin 2018

Generic method to get a list for each Entity Framework class

I have this method for my Entity Framework class (v6) to get all the elements in this table from my database:

List<FooClass> GetAll_FooClass()
{
    return dbContext.FooClass.ToList();
}

So what I would like is a method which would do the same but would be usable on each entity class I have (individually I mean).

Is it possible and if so, how can I implement it ?

EDIT: I seem to have mistaken FooClass for a class whereas it is a property of the dbContext object.

public class MyDbContext : DbContext
{
    public MyDbContext()
    { }

    public virtual DbSet<FooClass> FooClass { get; set; }
}

So I'm trying to use System.Type right now (PropertyInfo and MethodInfo).





Aucun commentaire:

Enregistrer un commentaire