Use of Dbcontext in Entity Framework
The Dbcontext is the primary class for communicating with database.It uses System.Data.Entity.DbContext class.
The EntityFramework.dll is released through Microsoft Nuget packages.
What is context class?
The class which is derived from DbContext is called context class in entity framework.
The DbContext class acts as a mediator or bridge between your domain or entity class and database.
The following are the DbContext activities:-
It converts "LINQ to Entities" to "SQL query" and sends them to database.
Keeps track of changes that occurred on the entities after querying from the database.
Performs the Insert, Update and Delete operations to the database, based on entity states.
It provides First level cache by default.
What is First level cache?
it means stores the entities retrieved during the first contact with context class.
Cache library allow you to cache the result of a LINQ query, usually in the memory, and re-use the cached result for subsequent calls.
It manages reletionships using CSDL,SSDL and MSL
SSDL in DB-First or Model first
Fluent API in Code first
The CSDL,SSDL and MSL sections in EDMX file:
CSDL MSL SSDL in Entity Framework:-
Conceptual Schema Definition Language(CSDL):
It contains Model classes and relationships.The file extension is .csdl
Storage Schema Definition Language(SSDL):
It is storage model otherwise called as logical model.
it includes Tables,Views,StoredProcedures and their relationships.The file extension is .ssdl
Mapping Specification Language(MSL):
It is mapping between Conceptual and Storage models.The file extension is .msl
Converts raw data from the database into entity objects.