Recently learned MVC5, followed by the book to do examples of a small problem, from a variety of sites found after the solution.
The book is an ASP. NET MVC5 Advanced Programming, P67 executes the scaffolding template, right-click Controller to add Controllers-MVC5 controller with view.
This problem occurs when you add the last:
After using this method, I still can't http://stackoverflow.com/questions/34333966/ error-key-already-exists-in-table-when-scaffolding-controller-vs2015
But I find this not the code in the book, just two more lines. The two lines were then removed. It's OK. In fact, the book says this method, but the book says "for example, the following classes can be used to ..." "The whole feeling is not like steps ...
Summary of the solution: Add Class Musicmodeldb below the Modles, that is, the data context to be used later (before adding the time I still think that no such class how to out of thin air. Is wrong).
The code in MUSICMODELDB:
Namespace Mvcmusicstore1.models
{
public class Musicstoredb:dbcontext
{
Public dbset<album> Albums {get; set;}
Public dbset<artist> Artists {get; set;}
Public dbset<genre> genres {get; set;}
}
}
This will allow you to add a success. In fact, this class should be automatically added to the program, but I did not succeed, manually added in advance.
Error running selected code generator key already exists in table