p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET MVC 4 (http://p2p.wrox.com/forumdisplay.php?f=712)
-   -   Chapter 4 - Error Creating StoreManager (http://p2p.wrox.com/showthread.php?t=88925)

jkennedy December 4th, 2012 05:58 PM

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?


Kaiser December 28th, 2012 12:30 PM

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.

Tom Wolfe January 10th, 2013 02:41 PM

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

Rohan Parkes March 21st, 2013 10:59 PM

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.

JonGalloway May 7th, 2013 12:50 PM

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.

regal60740 August 29th, 2013 05:57 PM

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!

Oleg Kolpashchikov August 31st, 2013 04:00 PM


You are just adding namespace;

// page 77
public class MusicStoreDB : DbContext

What is wrong with that? Obviously, you could have added "using MvcMusicStore;" at the top

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.

RKevinBurton June 23rd, 2014 05:29 AM

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?

All times are GMT -4. The time now is 04:16 PM.

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