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

1 comment:


  1. I am really impressed with your writing skills and also with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the excellent quality writing, it's rare to see a nice blog like this one these days. aol mail login

    ReplyDelete

Powered by Blogger.