Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 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 April 9th, 2016, 03:18 PM
Authorized User
 
Join Date: Dec 2015
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 14 Entity Framework

So far I really like this book and have written code for my own web site following Imar Spaanjaars code line for line with just various names (Web site name, database name etc) changed. I've now moved through Chapter 14 to using Entity Framework and have started pounding my head against the wall. Here's the problem: I added the ADO.NET Entity Data Model to my App_Code file and see the resulting three files added, in my case TRT.Context.tt, TRT.edmx, TRT.tt. Upon going to the Web.config file I also see a large number of elements have been added that apparently deal with the Entity Framework. Ok, so far so good. Now as directed I go to the All.aspx file in the Reviews folder (in my case the "AllSongs" in the "Songs" folder. I then start by adding the using statement to the page_load event handler:

using(TRTEntities myEntities = new TRTEntities());While typing I immediately get the error message "The type or namespace name 'TRTEntities' could not be found (are you missing a using directive or an assembly reference?)". I've tried innumerable measures in an attempt to overcome this error including.

1) Deleting the files in the App_Code file and all lines of code written into the Web.config file and then starting over (I've done this a number of times and with different names for the ADO.NET Entity Data Model name each time getting the same error message).
2) Repairing (reloading) the entire Visual Studio Express 2013.

I might also mention that I went through this step initially and everything worked. However, I couldn't get it up loaded onto my online website and thought there might be a problem with the Entity Framework part and deleted that code and started again: That’s when the problems began.

Is there anyone out there that could provide some guidance as to where how I might proceed to resolve this problem? Any help would be greatly appreciated.

Last edited by trtyler; April 9th, 2016 at 03:23 PM..
 
Old April 10th, 2016, 06:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look here:

hapter 14 Third Try It Out A Simple Model Binding Application, page 505

There are a bunch of questions and answers in that thread that may relate to your situation. Take a look and then post here if you have more questions.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 10th, 2016, 04:27 PM
Authorized User
 
Join Date: Dec 2015
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Smile Issue Resolved (for now)

Thank you for your rapid response Imar.

Ok, what a battle. The threads you pointed to did give me some ideas but in the end I finally did a careful observation of Figure 14-1 and discovered that Visual Studio was providing its own name for entity connection i.e. essentially the name of the database. In my case this was somewhat complicated by the constraints of my online website (I'm trying to do as much as possible to make the migration to the website as uniform as I can). After a number of additional attempts I found I needed the name I provided for the ADO.Net Entity Data Model to be exactly the the same as that of the entity connection (Although I think maybe Visual Studio enforces that anyway). Finally I obviously found that the using statement required the same name. As an aside, it also took a little time to discover that the using statement in the page_load event handler does not accept a semicolon at the end. I don't understand this because the using directives for webforms do require the ending semicolons and I thought all C# statements required semicolons, but I guess this using line is not really a statement

Again, thank you for your rapid response and after a week I am perhaps again on tract.
 
Old April 11th, 2016, 04:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> As an aside, it also took a little time to discover that the using statement in the page_load event handler does not accept a semicolon at the end.

This is a different use of using. At the top of the file, the using statement is used to bring a namespace into scope. Those lines should be ended in a semi colon.

The using from this exercise is to encapsulate an object and ensure it's disposed of at the end. This doesn't require semi-colons, much like the curly braces in an if statement don't. For example:

using (var someVariable = new SomeClassThatImplementsIDisposable())
{

}

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14, first try it out - Compilation Error Planet Wrox - Entity Framework PSK BOOK: Beginning ASP.NET 4.5 : in C# and VB 18 April 12th, 2015 04:42 PM
Chapter 14 ADO Entity Harpist BOOK: Beginning ASP.NET 4 : in C# and VB 6 December 14th, 2014 08:18 AM
PLEASE HELP WITH THE ERROR IN Chapter 14 LINQ and the ADO.NET Entity Framework Tobi BOOK: Beginning ASP.NET 4 : in C# and VB 2 February 19th, 2014 08:03 AM
Chapter 14 - Using Data Controls with the Entity Framework nudirection BOOK: Beginning ASP.NET 4.5 : in C# and VB 3 July 11th, 2013 02:29 AM
Chapter 14 Linq and ado.net entity framework pandukal21 BOOK: Beginning ASP.NET 4 : in C# and VB 8 January 28th, 2011 05:19 AM





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