What are exactly DbContext and DbSet in EF? [Answered]
I was wondering if getting the DbContext is getting the entire DB and using DbSet is using the single tables. Is this correct?
4 Replies
There's a lot of nuance but the short answer is yes, that's a high level view of it
A Context may have as much or as little of the database as needed, and a DbSet may not represent the full table in the case of query filters/etc
also a single DbSet may represent more than 1 table (although this is definitely more advanced setups territory)
Generally speaking:
-
DbContext
abstracts the database
- DbSet
abstracts the table✅ This post has been marked as answered!