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?
Firstly Add Reference to
System.Data.Entityin your project by Right Click your project in Solution explorer and Select Add Reference. Then use theusingstatement as below:Then write your Context Class as:
Ref: Using DbContext in EF 4.1 Part 1: Introduction and Model