How to inherit from the DbContext Class
10,125
Firstly Add Reference to System.Data.Entity
in your project by Right Click your project in Solution explorer and Select Add Reference. Then use the using
statement as below:
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
Then write your Context Class as:
public Class SampleEF : DbContext
{
}
Ref: Using DbContext in EF 4.1 Part 1: Introduction and Model
Comments
-
V G S Naidu almost 2 years
I am working on MVC and in the model I created a class that uses Entity Framework. I am trying to inherit from DBContext class but it is showing an error saying: "The type or Namespace name DBContext doesn't exist". I also added the "System.data.Entity " namespace.
Example like :
public Class SampleEF :DBContext //Showing error { }
Can you please tell me how to use the DBContext class to work with EF?
-
Niranjan Singh about 12 yearsit's is good. and one thing consider to upvote and accept the answer here if it help you to solve your problem, it will encourage other to help..