Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:00:13+00:00 2026-06-15T06:00:13+00:00

I saw a piece of code that mixes DbSet and DbContext together. I am

  • 0

I saw a piece of code that mixes DbSet and DbContext together. I am not strong on Entity Framework. I thought that they are different things.

Can somebody give me a little explanation?

public class testContext : DbContext
{
    public testContext();

    public string IPAddress { get; set; }
    public DbSet<WSettings> Settings { get; set; }
    public string UserName { get; set; }

    public override int SaveChanges();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:00:15+00:00Added an answer on June 15, 2026 at 6:00 am

    Intuitively, a DbContext corresponds to your database (or a collection of tables and views in your database) whereas a DbSet corresponds to a table or view in your database. So it makes perfect sense that you will get a combination of both!

    You will be using a DbContext object to get access to your tables and views (which will be represented by DbSet’s) and you will be using your DbSet’s to get access, create, update, delete and modify your table data.

    If you have 10 tables in your database and your application works with 5 of them (let us call them Table1 – Table 5) it would make sense to access it using a MyAppContext object where the MyAppContext class is defined thus:

    public class MyAppContext : DbContext
    {
        public MyAppContext () : ;
    
        public DbSet<Table1> Table1 { get; set; }
        public DbSet<Table2> Table2 { get; set; }
        public DbSet<Table3> Table3 { get; set; }
        public DbSet<Table4> Table4 { get; set; }
        public DbSet<Table5> Table5 { get; set; }
    }
    

    Note that, for instance, the identifier Table1 is used both as the name of a type and as a name of a property in the defined context type. What you see above is quite typical. An example of a class that corresponds to a table schema is given below:

    public class Table1 
    {
       public int Id {get; set;}
       public string AStringField {get; set;}
       //etc.
    }
    

    Have a look here for more information: http://entityframeworktutorial.net/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw a piece of code that stuck me as odd. What does switch(!0)
I saw a few old code snippets in a piece of software that no
I saw a piece of code which was written like this: if (from n
I saw a piece of code from a website which is in php. In
I saw a piece of Scala code with manifest syntax as follows. I do
I saw a similar piece of perl code in the code base and wanted
I saw that even by writing separate commands, we can combine two different types
I'm trying to write a piece of code that reads a file line by
I just saw a piece of code: public class MyApplication extends Application { private
I just stumble on a piece of code which I never saw before: document.execCommand('Copy');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.