I just started working with Entity Framework 6.1.2. I am using code first migration. I have around 78 entities in database. My question is that is there any way we can make the DbSet property generic in DatabaseContext class so I don't have to define all 78 properties? For example
public class DatabseDbContext : DbContext
{
public DbSet<Users> Users { get; set; }
public DbSet<Roles> Roles { get; set; }
public DbSet<Models> Models { get; set; }
public DbSet<Rights> Rights { get; set; }
}
I don't want to make all these properties. Instead I want one generic property or function to return the DbSet of respective type. Thanks in advance!
DbContextalready contains a generic methodSet<T>(), you can call that directly as it is public. Example:var allUsers = contextInstance.Set<User>().ToList();Is that what you are looking for?