 |
BOOK: Professional ASP.NET MVC 4
 | This is the forum to discuss the Wrox book Professional ASP.NET MVC 4 by Jon Galloway, Phil Haack, Brad Wilson, K. Scott Allen; ISBN: 978-1-118-34846-8 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional ASP.NET MVC 4 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
|
|
|
|

December 4th, 2012, 05:58 PM
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 4 - Error Creating StoreManager
On Chapter 4, page 74 I'm creating the StoreManager Controller as described and I've created the classes for Album, Artist and Genre as described earlier, on the Add Controller dialog I've selected the Template "MVC controller... using EF", Model Class is "Album" and I've defined a new Data context class.
When I click Add I get the following error...
"Unable to retrieve metadata for 'MMS.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."
I thought EF derived Primary keys based on the class properties definition?
Thanks,
John
|

December 28th, 2012, 12:30 PM
|
Registered User
|
|
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You need to look at the Classes you created for Album, Artist & Genre. It could be that you have made a typing error and the ID fields are not been seen as foreign keys due to different spellings or missing properties.
You also need to make sure you select the correct template :-
MVC controller with read/write actions and views, using Entity Framework.
Also, Check that you have the latest version of Entity Framework 4.5 installed via NuGet.
Hope this helps.
|

January 10th, 2013, 02:41 PM
|
Registered User
|
|
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Figure 4-5...
Perhaps like me Figure 4-5 on page 79 threw you off. I kept making the <New data concept> appear exactly as seen in the figure. I kept getting the exact error message you describe. I would consistently put MvcMusicStore.Models.MusicStoreDBContext into the field. Wrong! After a few hours off attempts, I just directly typed in MusicStoreDB into the field and clicked OK AND it finally scaffolded without the error. Bottom-line... type in MusicStoreDB and click OK. You should be good...
|

March 21st, 2013, 10:59 PM
|
Registered User
|
|
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm encountering this problem too. I was in fact also making the mistake of typing in the fully-qualified name, but unfortunately, using "MusicStoreDB" didn't fix it for me. I still get the error message about not having an id. I've also tried adding the [Key] data annotation. This didn't help, (and shouldn't be necessary in this situation anyway).
According to NuGet, I have Entity Framework 5 installed.
UPDATE: I got it to work. As someone pointed out in another thread, you need to recompile the project after adding your classes and before generating the controller. There was actually some indication of this in the text when it was mentioned that the MVC tools use reflection. Of course, the classes need to be compiled for this to work.
Last edited by Rohan Parkes; March 21st, 2013 at 11:47 PM..
|

May 7th, 2013, 12:50 PM
|
Wrox Author
|
|
Join Date: Oct 2006
Posts: 36
Thanks: 1
Thanked 5 Times in 5 Posts
|
|
Recompile
Rohan -
Glad you got that to work. Visual Studio determines the types that show up in the dropdown by reflecting over the assemblies, so it only sees the classes (or changes to the classes) when you recompile.
|

August 29th, 2013, 05:57 PM
|
Registered User
|
|
Join Date: Aug 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 4 - Error Creating StoreManager
I was getting the same error about "Album" not having a key". I found 2 errors in the book. One for Data Context Class: should be "MvcMusicStore.MusicStoreDB" and one for Model Class: should be "Album (MvcMusicStore)".
I spent hours working on this problem. I wish the authors would realize that many of us are very new to programming and need accurate information to build these programs. It makes me sick to work for hours on programs only to find out later that an error in the book is the real problem.
Once I made the above changes, the scaffolding finally worked. Man if I had to do this in the real world, I'd probably get fired for taking too long!
|

August 31st, 2013, 04:00 PM
|
Authorized User
|
|
Join Date: Jun 2013
Posts: 36
Thanks: 1
Thanked 4 Times in 4 Posts
|
|
1.
MvcMusicStore.MusicStoreDB
You are just adding namespace;
Code:
// page 77
public class MusicStoreDB : DbContext
What is wrong with that? Obviously, you could have added "using MvcMusicStore;" at the top
2.
Album (MvcMusicStore)
What do you mean by that? "Album" is a class, not a method. How can it be followed by something in parentheses?
Please specify the page number where you found wrong code and explain how you corrected it.
|

June 23rd, 2014, 05:29 AM
|
Registered User
|
|
Join Date: Jul 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Once I compiled as suggested the scaffolding process worked without error. However, the MusicStoreDB.cs file is NOT in th Models folder as suggested on page 79. For me it was put in the root of the project. Did I do something wrong?
|
|
 |
|