Error running selected code generator key already exists in table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.