Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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 June 22nd, 2011, 06:32 PM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default DataPager Control

Page 521.
First, thank you for your responses. Imar, my first posting was in the wrong section, so I'm doing it here.

I tried rebuilding my database model from scratch, as you suggested. The problem didn't change. I'll refresh your memory in a moment.

I then have spent the past 10 days diligently starting over with Chapter 1 and up to page 521. I still get the same problem. The problem is:

"Server Error in '/' Application.
--------------
A property with name 'PhotoAlbumId' does not exist in metadata for entity type 'PlanetWroxModel.Picture'.

I'm totally lost on this one. My configuration is:

MS SQL Server 2010 Pro.
VS 2010 Pro
Windows 7 Pro
Plenty of RAM, HDD, Graphics, etc.

Any help would be GREATLY appreciated as I'm going to be starting my classes in a short time.

The old story of them that can "do", them that can't "teach". Used to be I COULD, but now I teach. HELP!
Reply With Quote
  #2 (permalink)  
Old June 22nd, 2011, 06:40 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

When you create the model, do yo usee an option to include foreign keys?

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
  #3 (permalink)  
Old June 22nd, 2011, 07:19 PM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default

Yes, and I set my foreign keys, or so I thought. Is there a simple way to check while in VS?
Reply With Quote
  #4 (permalink)  
Old June 22nd, 2011, 07:24 PM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default

I just checked in the server explorer and the relationship line shows "Relationship 'FK_Picture_PhotoAlbum' between 'PhotoAlbum' and 'Picture"

Should be it.

I just went back and deleted the relationship and re-created it showing PhotoAlbumId as the foreign key in the Pictures table. Got the same error.

Last edited by david.rowley; June 22nd, 2011 at 07:31 PM..
Reply With Quote
  #5 (permalink)  
Old June 22nd, 2011, 08:04 PM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default

Just for grins I made a slight change in the asp code on the PhotoAlbums/Default.aspx page.

Original code under asp:EntityDataSource in the <WhereParameters>
is: <asp:ControlParameter ControlID="DropDownList1" Name="PhotoAlbumId".

I changed the PhotoAlbum Id to PhotoAlbumID and get the following error:


Server Error in '/' Application.

For the EntityDataSource, if the query specifies a projection and paging is enabled, a sort expression must be defined. Either set the OrderBy property or set AutoGenerateOrderByClause to true.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: For the EntityDataSource, if the query specifies a projection and paging is enabled, a sort expression must be defined. Either set the OrderBy property or set AutoGenerateOrderByClause to true.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: For the EntityDataSource, if the query specifies a projection and paging is enabled, a sort expression must be defined. Either set the OrderBy property or set AutoGenerateOrderByClause to true.]
System.Web.UI.WebControls.EntityDataSourceQueryBui lder`1.ApplyOrderByAndPaging(ObjectQuery`1 queryT) +50434
System.Web.UI.WebControls.EntityDataSourceQueryBui lder`1.CompleteBuild(ObjectQuery`1 queryT, ObjectContext context, Boolean computeCount, Boolean wasExtended) +92
System.Web.UI.WebControls.EntityDataSourceView.Con tinueSelectTyped(DataSourceSelectArguments arguments, EntityDataSourceQueryBuilder`1 queryBuilder, ObjectQuery`1 queryT, Boolean wasQueryModified) +91
System.Web.UI.WebControls.EntityDataSourceView.Exe cuteSelectTyped(DataSourceSelectArguments arguments, Creator qbConstructor) +2138
System.Web.UI.WebControls.EntityDataSourceView.Exe cuteSelect(DataSourceSelectArguments arguments) +333
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.Perform Select() +143
System.Web.UI.WebControls.ListView.PerformSelect() +113
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +74
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +66
System.Web.UI.WebControls.ListView.CreateChildCont rols() +55
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496


If I change it back to PhotoAlbumId then the old error crops up again.
Reply With Quote
  #6 (permalink)  
Old June 22nd, 2011, 11:19 PM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default

Well, I tried another way. I deleted both tables from the database. I went back and recreated them, exactly. I set the primary keys. I set the identity to yes. I created a foreign key relationship in the database diagrams. I went to the model and imported both tables, but I now notice that there are no navigation properties on either the Picture or the PhotoAlbum databases. There is also no relationship line created.

So, I have deleted everything pertaining to the new tables and started over, 4 times now, with the same results.

Must be doing something wrong, but don't know what.
Reply With Quote
  #7 (permalink)  
Old June 23rd, 2011, 05:46 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you send me a zipped copy of the website? My guess is that you're setting up the relationships in the database incorrectly, but it's hard to tell exactly without seeing the project.

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!
Reply With Quote
  #8 (permalink)  
Old June 23rd, 2011, 11:24 AM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default

It's been sent to your e-mail address.
Reply With Quote
  #9 (permalink)  
Old June 24th, 2011, 05:24 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi David,

When I run your site as-is in my browser, I see two issues:

1. ManagePhotoAlbum.aspx?PhotoAlbumID=1

Results in the error

Quote:
'PhotoAlbum' is not a member of type 'PlanetWroxModel.Picture' in the currently loaded schemas. Near simple identifier, line 6, column 4.
2. PhotoAlbums/Default.aspx

Results in the error:

Quote:
For the EntityDataSource, if the query specifies a projection and paging is enabled, a sort expression must be defined. Either set the OrderBy property or set AutoGenerateOrderByClause to true.
I can fix issue one by updating the model. Here's how:

1. Double-click PlanetWrox.edmx in App_Code to open the EF designer.

2. Right-click the canvas and choose Update Model From Database.

3. Make sure that "pluralize...." and "Include foreign key columns...." are checked.

4. Click Finish. This brings back the relationship between PhotoAlbum and Picture

5. Save all changes and build the site (right-click the project and choose Build Web Site)

I can now successfully create new albums and add pictures to them.

Issue 2 can be fixed as well. The error message says:

Quote:
Either set the OrderBy property or set AutoGenerateOrderByClause to true.
which is the key to the solution. In the book, the EntityDataSource control for the Pictures EntitySet has no "projection". E.g. it doesn't explicitly select columns. Your code does, which causes an issue. Two ways to fix this:

1. Delete the Select="it.[Id]..... " part from the EntityDataSource. EF will select the entire entity and all will work as expected.

2. Follow the suggestion from the error message and add an OrderBy clause, for example like this:
Select="...." OrderBy="it.[Id]"

This way, the control can successfully use projection to select only a subset of the entity's properties, while it can still use paging as the set of entities is now sorted.

Hope this helps. If not, or if there are other issues I haven't found, please let me know.

Quote:
I didn’t include any photos though.
Yes you did. About 20.5 MB of the 21 MB rar file you sent me ;-)

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
The Following User Says Thank You to Imar For This Useful Post:
david.rowley (June 24th, 2011)
  #10 (permalink)  
Old June 24th, 2011, 11:47 AM
Registered User
 
Join Date: Jun 2011
Posts: 10
Thanks: 2
Thanked 1 Time in 1 Post
Default

My apologizes on the photos. I checked and found that I removed them from the copy of the site and then forwarded the wrong copy. Ouch!

I'm just getting started on the day. I realize you are just finishing. I'll go through my coding and make the changes and get it to work. When I'm done I'll post my results.

However, can you tell me at what stage I went wrong? I re-did the entire book with the same results, so I'm missing something. I rebuilt the model 4 times with the same results. I must have missed something, and need to know what.

Thanks.

Oh, the University is taking my recommendation and we'll be using your book as a text. I just have to develop a curriculum around it and some test banks, etc., but I like what you have done and how you have done it. Thanks. It takes a lot of pressure off from me.
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
Click event not firing for Dynamic button control when it has validation control Gayathri79 ASP.NET 3.5 Basics 5 August 20th, 2010 06:58 PM
datapager for programatic listview digink BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 June 1st, 2010 02:07 AM
Datapager in Listview monika.vasvani ASP.NET 3.5 Professionals 0 March 10th, 2010 05:45 AM
Datapager in Listview monika.vasvani ASP.NET 3.5 Professionals 0 March 9th, 2010 09:31 AM
DataPager & PlaceHolder positions jsymons BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 25th, 2009 07:50 AM



All times are GMT -4. The time now is 11:45 PM.


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