 |
| 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
|
|
|

November 1st, 2013, 04:37 AM
|
|
Registered User
|
|
Join Date: Oct 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|

November 1st, 2013, 06:41 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

December 19th, 2013, 11:39 AM
|
|
Registered User
|
|
Join Date: Oct 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|

February 3rd, 2015, 12:24 PM
|
|
Registered User
|
|
Join Date: Feb 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |