 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : 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
|
|
|
|
|

May 4th, 2012, 04:21 AM
|
|
Authorized User
|
|
Join Date: Apr 2012
Posts: 12
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
ch 14: AllByGenre.aspx.cs
using (PlanetHarmonyEntities myEntities = new PlanetHarmonyEntities())
{
var allGenres = from genre in myEntities.Genres
orderby genre.Name
select new { genre.Name, genre.Reviews };
Repeater1.DataSource = allGenres;
Repeater1.DataBind();
}
I don't understand how the title of the reviews are fetched using genre object
plz help.
|
|

May 4th, 2012, 04:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
A Genre and a Review have a relationship in the database. Just as a Review a Genre, so has a Genre a collection of associated Reviews. This means that
myGenre.Reviews
would give you all the reviews that belong to that genre. And this is what the LINQ query does:
Code:
select new { genre.Name, genre.Reviews };
It selects a new anonymous object with two properties: a Name of the genre and a collection of all associated reviews. This means you can then loop over the result set and display all genre names. Within that loop, you can loop over all reviews for that genre and display their info, including the title.
Check out page 495 and further for a detailed explanation including a class diagram of the anonymous type as well as a diagram that shows the relationship between the genre's Name and the collection of reviews.
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

May 4th, 2012, 05:09 AM
|
|
Authorized User
|
|
Join Date: Apr 2012
Posts: 12
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
thanx for the quick reply sir,
still i dont get it fully, does it internally creating join between the tables?
|
|

May 4th, 2012, 05:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You created a relationship between the two tables. When you then create an Entity Framework on top of the database, code gets generated that links a Genre instance to a Review instance. Without the proper relationship between those tables, the two objects won't be related in your EF model either.
When the query then gets executed (remember, LINQ queries for EF are translated to SQL), EF indeed creates a query that joins these two tables.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

May 4th, 2012, 08:38 AM
|
|
Authorized User
|
|
Join Date: Apr 2012
Posts: 12
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
ch 14: managephotoalbum.aspx??? images are not displayed
for some reason, after navigating to ManagePhotoAlbum.aspx i m able to insert the required values in the textbox, and its updated in the picture table, but not showing in the page, neither the delete button etc.
(sorry for not posting it in separate thread)
Code: ManagePhotoAlbum.aspx
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/MasterPages/Frontend.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=PlanetHarmonyEntities"
DefaultContainerName="PlanetHarmonyEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures"
Where="it.PhotoAlbum.Id= @PhotoAlbumId"
oninserting="EntityDataSource1_Inserting">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="Id"
Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
|
|

May 4th, 2012, 08:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
(sorry for not posting it in separate thread)
|
Then why didn't you create a separate thread? Makes stuff easier to find and manage.
Anyway, I think the problem is in the parameter setup:
Code:
<asp:QueryStringParameter Name="photoAlbumId" QueryStringField="Id" Type="Int32" />
Notice how your code use Id as the query string field. The NewPhotoAlbum.aspx page passes PhotoAlbumId to this page instead. Change Id ito PhotoAlbumId and I think it should work.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

May 4th, 2012, 09:08 AM
|
|
Authorized User
|
|
Join Date: Apr 2012
Posts: 12
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
oh yes hvnt recognized it, many thanx to u. 
|
|
 |
|