DbContext class in Entity Framework in MVC

DbContext class is the primary class that is responsible for interacting with data as object, which includes change tracking, persisting data, managing relationship, caching, querying to the database. DbContext works as a bridge between your domain or entity classes and the database.
Syntax:-

public class RecordContext : DbContext
    {
        public RecordContext() : base("constr") { }



        public DbSet <record> Students { get; set; }
    }



base ("constr") - Constructs a new context instance using the given string as the name or connection string for the database to which a connection will be made.

constr - Is the name of connection string which we have passed.
 Lastly we added Dbset of Model name (record) which we created in Models folder


For more understanding learn Entity Framework in MVC with example 

DbContext class in Entity Framework in MVC DbContext class in Entity Framework in MVC Reviewed by NEERAJ SRIVASTAVA on 2:54:00 PM Rating: 5

No comments:

Powered by Blogger.