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: Beginning ASP.NET 4.5 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2015, 08:29 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Chapter 14 - page 503 (Try it out)

Hi,

I need some help with the “Try it out” on Chapter 14 - page 503.
The “using PlanetWroxModel” doesn’t work in All.aspx.cs
The namespace could not be found.

Code:
using PlanetWroxModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Reviews_All : BasePage
{
  protected void Page_Load(object sender, EventArgs e)
  {
    using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
    {
      var authorizedReviews = from review in myEntities.Reviews
                              where review.Authorized == true
                              orderby review.CreateDateTime descending
                              select review;
      GridView1.DataSource = authorizedReviews;
      GridView1.DataBind();
    }
  }
}
- Error:

Code:
Error	1	The type or namespace name 'PlanetWroxModel' could not be found (are you missing a using directive or an assembly reference?)	C:\BegASPNET\Site\Reviews\All.aspx.cs	1	7	Site

Error	2	The type or namespace name 'PlanetWroxEntities' could not be found (are you missing a using directive or an assembly reference?)	C:\BegASPNET\Site\Reviews\All.aspx.cs	13	12	Site
Reply With Quote
  #2 (permalink)  
Old March 8th, 2015, 08:32 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using:
Beginning ASP.NET 4.5 in C# and VB
Visual Studio 2013 Ultimate
Reply With Quote
  #3 (permalink)  
Old March 8th, 2015, 09:01 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

The Entity Framework has changed quite a bit between the version of the book (ASP.NET 4.5) and the version of .NET that you are using (4.5.1). Check out this thread and see if it helps: Your Book and VS Versions

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!
Reply With Quote
  #4 (permalink)  
Old March 18th, 2015, 11:29 PM
Registered User
Points: 31, Level: 1
Points: 31, Level: 1 Points: 31, Level: 1 Points: 31, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 5
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The code is wrong in the book.
You might not need to add the using planetwroxmodel, I didn't.

And in c# the line should be:

gridview1.datasource = authorizedreviews.tolist();

instead of

gridview1.datasource = authorizedreviews;

I'm using VS 2013. I think I used EF 5.0 instead of 6. If you add 6, you might get a different result. Also, but adding 6, it will be a pain to clear out off of the stuff it adds to your web.config file.
Reply With Quote
  #5 (permalink)  
Old March 20th, 2015, 10:58 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

The code in the book is correct for the version of EF and VS that it was targeting. However, EF 6 changed the rules a bit and no longer allows queries to be bound to a data source directly, so you need to call ToList to force execution of the query first.

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!
Reply With Quote
Reply


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
Chapter 14 page 508 khurramzaheer BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 3 January 5th, 2015 07:39 AM
Chapter 1 page 14 kermit1965 BOOK: Professional ASP.NET MVC 2 6 October 12th, 2010 10:10 AM
Chapter 14 Page 548 Try it Out andreas5 BOOK: Beginning ASP.NET 4 : in C# and VB 7 August 22nd, 2010 07:48 AM
Chapter 14:Page 481 try it out lstew452 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 June 20th, 2010 02:35 PM
Page 503: keyword SELECT missing dingemans BOOK: Beginning T-SQL with Microsoft SQL Server 2005 and 2008 ISBN: 978-0-470-25703-6 1 October 6th, 2009 01:12 PM



All times are GMT -4. The time now is 02:54 AM.


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