Using DbContext Set<T>() instead of exposing on the context

The Users property is added for convenience, so you don't need to remember what all of your tables are and what the corresponding class is for it, you can use Intellisense to see all of the tables the context was designed to interact with. The end result is functionally equivalent to using Set<T>.


You get a benefit with the former method when using Code-First migrations, as new entities will be detected as such automatically. Otherwise, I'm quite certain they are equivalent.


This is how I set my generic dbSet, works just fine

DbContext context = new MyContext();
DbSet<T> dbSet = context.Set<T>();

It is the generic version of something more explicit, such as

DbContext context = new MyContext();
DbSet<User> dbSet = context.Set<User>();

Either way, they are the same (when T is User)