The context class in Entity Framework is a class which derives from
DbContext in EF 6 and EF Core both. It is an important class in Entity Framework, which represents a session with the underlying database.
The following
SchoolContext class is an example of a context class.public class SchoolContext : DbContext { public SchoolContext() { } public DbSet<Student> Students { get; set; } public DbSet<StudentAddress> StudentAddresses { get; set; } public DbSet<Grade> Grades { get; set; } }
In the above example, theSchoolContextclass is derived fromDbContext, which makes it a context class. It also includes an entity set forStudent,StudentAddress, andGradeentities.The context class is used to query or save data to the database. It is also used to configure domain classes, database related mappings, change tracking settings, caching, transaction etc.
No comments:
Post a Comment