Neeraj Verma
Neeraj Verma

Reputation: 263

Resolved: There was an error generating '..Context'. Try rebuilding your project

I am learning Insert ,update, delete using Entity Framework in MVC from

https://www.youtube.com/watch?v=8f4P8U1a2TI

I add new Entity Framework and after that adding new Controller.

here is my Setting for adding new Controller

enter image description here

when I save adding Controller . Error Comes ..

There was an error generating 'MvcApplication1.Models.EmployeeContext'. Try rebuilding your project.

EmployeeContext.cs

 public  class EmployeeContext :DbContext
    {
        public DbSet<Employee> Employees { get; set; }
    }

(Employee class is in seperate Assembly)

Solutions i tried :

  1. Cannot add controller in ASP.NET MVC project

it says some special constructor in dbcontext caused problem... i dont have any

  1. uninstall and reinstall entity framework from nuget several times

3.Database.SetInitializer() placed in Application_Start method in Global.asax.cs

whats Wrong ? please suggest ...

Upvotes: 1

Views: 5002

Answers (1)

Neeraj Verma
Neeraj Verma

Reputation: 263

OK , Resolved .. Here what i did

  1. I removed Model Class , Context Class and add , delete , save operations ..which were manually created . Entity Framework Auto Generates these things . so the conflict was occuring...

  2. while adding New controller ..In DataContext Class Section ..Connectionstring name should be filled which is Auto Generated by Entity Framework . i was filling incorrect thing

Hope that might be helpful

Upvotes: 1

Related Questions