Add Controller in MVC4 not working

前端 未结 11 544
一向
一向 2020-11-30 08:58

I\'m using VS 2010 Premium. I have a MVC4 project using SqlCe 4.0 with a entity framework model.

Model is:

  public class ProjectBuild
    {
       p         


        
相关标签:
11条回答
  • 2020-11-30 09:30

    I feel like this is related, but I used the solution above to fix the problem and let me build controllers again. The problem I had after that was that I couldn't seem to find my SQL Compact database after that in server explorer. It appeared to be working when I added the application, but I couldn't find it. Once I removed the constructor: public class SchoolContext : DbContext { public SchoolContext() : base("School") { } .

    I was able to see the db again. I'm still in development and need to add more controllers, so I'll have to use it again, I guess. But this took me all morning to figure out why I suddenly couldn't see the database in server explorer anymore.

    0 讨论(0)
  • 2020-11-30 09:34

    You should always initialize the superclass with base(string). Also found out that the name of connectionString in Web.config may not be same as the String you send to the super class contructor.

    So for example :

    <add name="MovieDBContext"  ....... />
    
    public class MovieDBContext : DbContext
    {
       public MovieDBContext() : base("Movie") { }
    }
    

    So you see, the "MovidDBContect" is different from "Movie".

    0 讨论(0)
  • 2020-11-30 09:40

    A note if it helps anyone. I just had this problem.

    This Fixed it: 1. Commenting out the Connection String 2. Rebuild Website without Connection String 3. Add Controller 4. Uncomment Connection String 5. Rebuild Website

    All Works Fine.

    0 讨论(0)
  • 2020-11-30 09:41

    This is going to seem like the dumbest thing, but do you have a connection made to your database elsewhere? I was running into this same exact problem. I had the database open in the Server Explorer view (I had made a connection to my SDF file). Once I closed this connection, everything worked perfectly.

    0 讨论(0)
  • 2020-11-30 09:44

    I changed the name of my connection string back to DefaultConnection and then it worked, I tried at first to add the default constructor but received some warning about not having the correct assemblies references to.

    0 讨论(0)
提交回复
热议问题