Wrox Programmer Forums
| 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 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 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
 
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
 
Old March 8th, 2015, 09:01 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
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.
 
Old March 20th, 2015, 10:58 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!




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





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