Search code examples
entity-frameworkcode-first

What is this ApplicationDbContext anyway? Difference between it and XxxDbContext during Entity Framework code first?


kinda new to this. So a bit confused. i couldn't find the information i need regarding this ApplicationDbContext, what is it & how is it used? Thanks a lot.

Also, cannot see the part of code where Entity Framework actually connects to database, retrieve & store the data? All i saw is new DbContext() and DbSets are ready for use.


Solution

  • DbContext is the base class of all the Entities which are created by EF Database First approach. It acts as a bridge between your domain entities and database tables to retrieve, update and store the data. When creating a DbContext instance you need to pass the DB ConnectionString as a parameter. Generally we create a deriving class of DbContext class and pass the ConnectionString as below :

     protected DbContextBase(string connectionString) : 
            base(connectionString)
        {
        }
    

    Please refer the below link, It has a very detailed explanation of the DbContext() and easy to understand :

    http://www.entityframeworktutorial.net/EntityFramework4.3/dbcontext-vs-objectcontext.aspx