VS 2013 Controller Scaffolding Fails for the ApplicationUser Model (Multiple object sets per type are not supported)

后端 未结 8 2435
死守一世寂寞
死守一世寂寞 2020-12-08 11:07

In a VS 2013 RTM, MVC 5 project with EF 6, I tried to scaffold a controller based on the ApplicationUser (default with individual accounts authentication). Both Applic

8条回答
  •  [愿得一人]
    2020-12-08 11:34

    What you can also do: Create an empty controller, and add the code for the DataContext yourself

        protected ApplicationDbContext db { get; private set; }
    
        public HomeController() : this(new ApplicationDbContext())
        {
        }
    
        public HomeController(ApplicationDbContext db)
        {
            this.db = db;
        }
    

    Then create your methods like Index, Create and so on, and create the views with right-clicking and "Add view..." for each. Scaffold your views with the list, create, whatever template that is appropriate and choose the ApplicationUser as an model.

    Important: Delete the entry in "Data context class", or you will get a similar error again. But if you leave the "Data context class" empty, the scaffolding of the view will work out fine.

提交回复
热议问题