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 December 16th, 2015, 01:34 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 14: A Simple LINQ to Entities Example

Performed steps 8, 9, and 10 of the subject Try it Out. At step 10 when I view in the browser, I get the error message that the type or namespace name 'PlanetWroxEntities' could not be found (are you missing a using directive or an assembly reference?). The problem is from Line 12 of All.aspx.cs

Here is the code from All.aspx.cs:
Code:
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.ToList();
        GridView1.DataBind();
      }
    }
}
Here is the code from All.aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true"
CodeFile="All.aspx.cs" Inherits="Reviews_All" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</asp:Content>


Please help me fix the problem.
 
Old December 16th, 2015, 09:31 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 14: A Simple LINQ to Entities Example

I am troubleshooting the problem and think I might have found a possible cause. Here is my web.config file:
Code:
<connectionStrings>
    <add name="PlanetWroxConnectionString1" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\PlanetWrox.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="PlanetWroxEntities" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="PlanetWroxEntities1" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="PlanetWroxEntities2" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
There are three PlantWroxEntities as I made several tries to get it right.

Here is the PlantWrox.Context.cs file:

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

public partial class PlanetWroxEntities2 : DbContext
{
public PlanetWroxEntities2()
: base("name=PlanetWroxEntities2")
{
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}

public virtual DbSet<Genres> Genres1 { get; set; }
public virtual DbSet<Reviews> Reviews1 { get; set; }
}

I think that the bold statement should refer to "PlanetWroxEntities" instead of "PlanetWroxEntities2".
 
Old December 16th, 2015, 10:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> I think that the bold statement should refer to "PlanetWroxEntities" instead of "PlanetWroxEntities2".

Yes, either that, or update your code to use PlanetWroxEntities instead.

When you delete the model to start over, VS doesn't delete the connection string. Then when you add it, it finds PlanetWroxEntities in the web.config and adds a sequential number to make it unique. If you really want to start over, delete your edms, then delete your connection strings and then add the model again.

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 December 17th, 2015, 12:26 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Smile Chapter 14: A Simple LINQ to Entities Example

Thank you, Imar.

I chose to start all over again, and it worked.

Thank you once more.





Similar Threads
Thread Thread Starter Forum Replies Last Post
LINQ to Entities begaspnet BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 2 July 21st, 2014 04:11 PM
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
A simple LINQ to Entities Example (Problem in this Try it out) CompactDisc20 BOOK: Beginning ASP.NET 4 : in C# and VB 5 July 6th, 2013 10:16 AM
Chapter 14 LINQ ADO.NET EF ecdhyne BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 June 21st, 2013 03:45 PM
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.