I am trying to do the try it out section, "A Simple EntityDataSource Application" but when I run the NewPhotoAlbum.aspx page I receive the following error:
'PhotoAlbum' is not a member of type 'PlanetWroxModel.Picture' in the currently loaded schemas. Near simple identifier, line 6, column 4.
I have checked my where clause as suggested in another post about this, but I cannot see the issue. Can you offer me any help please?
My code is as follows:
ManagePhotoAlbum.aspx
Code:
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/MasterPages/ManagementMaster.master" AutoEventWireup="true" CodeFile="ManagePhotoAlbum.aspx.cs" Inherits="ManagePhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" DataSourceID="EntityDataSource1" InsertItemPosition="LastItem">
<InsertItemTemplate>
<li style="">Description:
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
<br />ToolTip:
<asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
<br />ImageUrl:
<asp:TextBox ID="ImageUrlTextBox" runat="server" Text='<%# Bind("ImageUrl") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</li>
</InsertItemTemplate>
<ItemTemplate>
<li style="">
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
ToolTip:
<asp:Label ID="ToolTipLabel" runat="server" Text='<%# Eval("ToolTip") %>' />
<br />
ImageUrl:
<asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("ImageUrl") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=PlanetWroxEntities" DefaultContainerName="PlanetWroxEntities1" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures" Where="it.PhotoAlbum.Id = @photoAlbumId" OnInserting="EntityDataSource1_Inserting">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
NewPhotoAlbum.aspx
Code:
<%@ Page Title="New Photo Album" Language="C#" MasterPageFile="~/MasterPages/ManagementMaster.master" AutoEventWireup="true" CodeFile="NewPhotoAlbum.aspx.cs" Inherits="NewPhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="EntityDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" InsertVisible="false"/>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=PlanetWroxEntities1" DefaultContainerName="PlanetWroxEntities1" EnableFlattening="False" EnableInsert="True" EntitySetName="PhotoAlbums" OnInserted="EntityDataSource1_Inserted">
</asp:EntityDataSource>
</asp:Content>
NewPhotoAlbum.aspx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PlanetWroxModel;
public partial class NewPhotoAlbum : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
{
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;
Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}",myPhotoAlbum.Id.ToString()));
}
protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e)
{
int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
Picture myPicture = (Picture)e.Entity;
myPicture.PhotoAlbumId = photoAlbumId;
}
}