Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
|
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 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
 
Old October 22nd, 2010, 01:52 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default p. 49 - EntityContainer name not found error

Hello,

Probably an easy question, but I'm definitely new to this, so here goes.

Trying to execute the request shown on p. 49 of the text, where you go to the URL http://localhost:44593/dinners/details/9999. I've double-checked my code against the sample source and the text and can't figure out what's wrong, but I'm getting this error:

"The specified default EntityContainer name 'NerdDinnerEntities' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName"

in this section of code:

Code:
Line 37:         /// Initializes a new NerdDinnerEntities object using the connection string found in the 'NerdDinnerEntities' section of the application configuration file.
Line 38:         /// </summary>
Line 39:         public NerdDinnerEntities() : base("name=NerdDinnerEntities", "NerdDinnerEntities")
Line 40:         {
Line 41:             this.ContextOptions.LazyLoadingEnabled = true;
I get into the constructor for DinnersController, and from there into DinnerRepository, but my constructor for NerdDinnerEntities fails...

My SQL Server database is up and running, I can browse the tables and see the data I've entered.

Any ideas?

Thanks,
Tony
 
Old October 22nd, 2010, 04:28 PM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

I'm guessing you may have moved NerdDinner.edmx from it's original location.

Take a look at your Web.Config. Search for NerdDinnerEntities. You may need to adjust namespace. I created my NerdDinner.edmx in the Models folder. My connection string in Web.Config looks like this:

Code:
    <add name="NerdDinnerEntities" connectionString="metadata=res://*/Models.NerdDinner.csdl|res://*/Models.NerdDinner.ssdl|res://*/Models.NerdDinner.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NerdDinner.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
Also check the namespace in NerdDinner.Designer.cs. It should match.
Code:
namespace NerdDinner.Models

Last edited by flyinhawaiian; October 22nd, 2010 at 04:34 PM..
 
Old October 22nd, 2010, 04:44 PM
Friend of Wrox
 
Join Date: Oct 2010
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Also note on Page 24, figure 1-46. The Model Namespace is shown as "NerdDinner.Models". (I used this one).

However, VS 2010 actually defaults it to "NerdDinnerModel" (w/o the period and singular).
 
Old October 25th, 2010, 04:21 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, cleaning up the .edmx file got me there. I forgot that I had mistakenly gone through the steps to create NerdDinnerEntities twice, and deleted the first one. The one left was named NerdDinnerEntities1 throughout, and I didn't catch every instance where that was used throughout the project. Cleaning up the .cs file was only half of it, I had to clean the .edmx as well.

Tony





Similar Threads
Thread Thread Starter Forum Replies Last Post
Correction to page 49 SeanDunn BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 3 January 3rd, 2010 01:00 AM
Subscript out of range: '[number: 49]' hameed Classic ASP Databases 2 August 5th, 2004 08:32 AM
Config Apache 2.0.49 for PHP4.3.5Win32 Domonsura BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 July 22nd, 2004 04:32 AM





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