Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Wrox Announcements and Feedback > Wrox Book Feedback
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 1st, 2013, 04:37 AM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 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, 10:39 AM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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, 11:24 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 03:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.