Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Wrox Announcements and Feedback > Wrox Book Feedback
|
Wrox Book Feedback A forum to submit feedback on Wrox books if other forums on P2P have been unable to address your book-specific needs. IF YOU ARE LOOKING FOR CODE DO NOT ASK "Where can I find the code for this book?" That question is answered here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Wrox Book Feedback section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 1st, 2013, 04:37 AM
Registered User
 
Join Date: Oct 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default problem - Professional ASP.Net MVC 4

Hello,
I wonder if some nice generous person could point me in the right direction with a problem I am having while working through the book: Professional ASP.Net MVC 4.
I have gotten to page 78 where I am instructed to create a new controller, ok no problem, but when I follow the instruction to select New Data Context, when I click add, I get an error thrown back at me in the form of:

Unable to retrieve metadata for 'MvcMusicStore.Models.Album'. One or more validation errors were detected during model generation:

-System.Data.Entity.Edm.EdmEntityType: : EntityType 'Album' has no key defined. Define the key for this EntityType.
-System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Albums' is based on type 'Album' that has no keys defined.


What I don't understand is, from what I am reading, the book says Visual Studio via Entity Framework is supposed to create the (database)table according to the existing code, it isn't something that pre exists and has been improperly designed. Am I wrong in assuming that the database model should be created based on the classes I have created?

Yes, I have set up the classes required as per the books instructions, but it looks like there is something severely flawed in the book, unless I have missed something which I honestly don't think I have.

Any pointers here would be greatly appreciated thank you.
Reply With Quote
  #2 (permalink)  
Old November 1st, 2013, 06:41 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I don't have the book, so I can't tell for sure what's going on. Does the sample use EF Code First (where you define the classes and then EF creates the database) or Database First (where you define the database and EF creates the classes)? In the former case, your class seems to miss an Id property (named Id, or something else but then it needs to be configured as a key). In the latter case, it seems that the database is missing the Id column.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old December 19th, 2013, 11:39 AM
Registered User
 
Join Date: Oct 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Starting over

Hi, thanks for the reply, I have now upgraded to vs2012 so am starting again from scratch, I expect there will be a different set of problems for me to post about, but thank you anyway.
Reply With Quote
  #4 (permalink)  
Old February 3rd, 2015, 12:24 PM
Registered User
 
Join Date: Feb 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

tuve el mismo problema

-System.Data.Entity.Edm.EdmEntityType: : EntityType 'Album' has no key defined. Define the key for this EntityType.
-System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Albums' is based on type 'Album' that has no keys defined.

Al crear un nuevo control, sucede que en mvc si no posees una base de datos a la cual conectarse, el crea una base de datos local, tomando los metodos y generando tanto el control como las vistas, es por eso que esta pidiendo que se reconosca una llave primaria.

MVC necesita que si se crea un método contenga una llave primaria, para esto se debe agregar ID al final del nombre del identificador, ejemplo, public int AlbumID { get; set; }, fíjese que AlbumID es asignado de este modo como llave primaria.

espero sirva.
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Professional ASP.NET MVC 4 bcbarnes Forum and Wrox.com Feedback 2 October 10th, 2012 07:01 PM
Errors while upgrade theBeerHouse mvc project form asp.net mvc 1.0 to 2.0 vanbach1304 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 0 April 20th, 2010 06:43 AM
do I need to override AuthorizeTag? - Asp.net MVC chobo2 ASP.NET 3.5 Basics 0 September 27th, 2009 10:28 PM
TheBeerHouse MVC preview ASP.NET MVC Website Programming Problem Design Solution jminatel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 July 18th, 2009 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.