Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Professional ASP.NET MVC 4
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 4th, 2012, 05:58 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old December 28th, 2012, 12:30 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Location: Newcastle, England
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

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.
  #3 (permalink)  
Old January 10th, 2013, 02:41 PM
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: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Wink 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...
  #4 (permalink)  
Old March 21st, 2013, 10:59 PM
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: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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..
  #5 (permalink)  
Old May 7th, 2013, 12:50 PM
Wrox Author
Points: 165, Level: 3
Points: 165, Level: 3 Points: 165, Level: 3 Points: 165, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: San Diego, CA, USA
Posts: 36
Thanks: 1
Thanked 5 Times in 5 Posts
Default 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.
  #6 (permalink)  
Old August 29th, 2013, 05:57 PM
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: Aug 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Angry 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!
  #7 (permalink)  
Old August 31st, 2013, 04:00 PM
Authorized User
Points: 175, Level: 3
Points: 175, Level: 3 Points: 175, Level: 3 Points: 175, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: St.Petersburg, Russia
Posts: 36
Thanks: 1
Thanked 4 Times in 4 Posts
Default

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.
  #8 (permalink)  
Old June 23rd, 2014, 05:29 AM
Registered User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: Madison, Wisconsin, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Creating a Database - Chapter 3 jamesmont BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 10 August 18th, 2011 08:50 AM
Chapter 7 - Creating Menu dvirdukhan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 8 May 18th, 2011 04:42 PM
Chapter 4. Creating User Interfaces example code error henrylu BOOK: Professional Android 2 Application Development 0 March 14th, 2011 09:57 AM
Chapter 19: Creating the Recordset NuovoData BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 0 May 5th, 2009 08:16 PM
Chapter 4 - creating a view MarieMcKeeth BOOK: Beginning Ruby on Rails 1 March 21st, 2009 06:56 PM



All times are GMT -4. The time now is 09:16 AM.


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