p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4.5 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=710)
-   -   Chapter 14 - page 503 (Try it out) (http://p2p.wrox.com/showthread.php?t=94238)

Ronin_PS March 8th, 2015 08:29 AM

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


Ronin_PS March 8th, 2015 08:32 AM

I'm using:
Beginning ASP.NET 4.5 in C# and VB
Visual Studio 2013 Ultimate

Imar March 8th, 2015 09:01 AM

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: http://p2p.wrox.com/book-beginning-a...-versions.html

Cheers,

Imar

oceanjams March 18th, 2015 11:29 PM

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.

Imar March 20th, 2015 10:58 AM

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


All times are GMT -4. The time now is 11:57 AM.

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