Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 20th, 2011, 08:07 PM
Registered User
Points: 35, Level: 1
Points: 35, Level: 1 Points: 35, Level: 1 Points: 35, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default chapter 14 Try It Out pg 505 step #4

My question concerns the Where clause: Where="it.PhotoAlbum.Id = @photoAlbumId" (see code below)

Why is it that the Where clause uses the property PhotoAlbum from the EntitySetName Pictures to get to Id field of table PhotoAlbum i.e. it.PhotoAlbum.Id. Why doesn't it use it.PhotoAlbumId directly, from table Pictures, in setting up the Where clause? What am I missing here?

Thanks ahead of time for any help offered.

Code:

</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=PlanetWroxEntities"
DefaultContainerName="PlanetWroxEntities" EnableDelete="True" EnableFlattening="False"
EnableInsert="True" EntitySetName="Pictures" Where="it.PhotoAlbum.Id = @photoAlbumId">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
Reply With Quote
  #2 (permalink)  
Old April 21st, 2011, 02:52 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

It's an Object Orientation versus a relational database approach that made me prefer one over the other:

I think this feels much more natural:

Code:
it.PhotoAlbum.Id
than this:

Code:
it.PhotoAlbumId
if you look at it from an Object Orientation perspective. In an OO world, a Picture has a PhotoAlbum property that refers to the album it belongs to. The fact it needs stuff like Ids to create the relation in the database is a side issue ;-), let alone the fact it needs a foreign key property called PhotoAlbumId which is merely there for optimization.

In earlier versions of EF, a Picture wouldn't even have a PhotoAlbumId property and you had to do some weird stuff to associate them (not query them as in your example). In EF4, the foreign property was added to make assigning one object to another easier. E.g.:

Code:
myPicture.PhotoAlbumId = 3;
rather than:

Code:
myPicture.PhotoAlbum = context.Albums.Where(p => p.Id == 3).First();
The inclusion of the foreign key property is done to optimize performance and make updates easier.

But, both solutions work fine. So it's perfectly OK to use PhotoAlbumId if that feels more natural to you.

Hope this helps.

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!

Last edited by Imar; April 21st, 2011 at 02:56 AM..
Reply With Quote
  #3 (permalink)  
Old April 21st, 2011, 10:35 AM
Registered User
Points: 35, Level: 1
Points: 35, Level: 1 Points: 35, Level: 1 Points: 35, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default chapter 14 Try It Out pg 505 step #4: Where clause

Thanks, Imar. Your explanation makes perfect sense. By the way, I am getting a lot out of your book. I highly recommended it to any beginner like me.
Reply With Quote
  #4 (permalink)  
Old April 21st, 2011, 02:28 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're welcome.

Quote:
By the way, I am getting a lot out of your book. I highly recommended it to any beginner like me.
That's good to hear. Tell all your friends, colleagues and Amazon.com.... ;-)

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 Page 470 Step 14 bagellady BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 8 September 17th, 2010 12:36 PM
Chapter 5 | Pg.158 - Step 2 jwriddle BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 30th, 2009 02:03 AM
Chapter 4|Pg.120 - Step 7 jwriddle BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 28th, 2009 04:30 PM



All times are GMT -4. The time now is 06:12 PM.


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