Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 January 6th, 2015, 06:34 PM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add Method Does Not Exist

I've been encountering this in the examples throughout the book. On page 569 (Chapter 15) and elsewhere we are instructed to call an Add method which (when we build the project) always produces an error because it doesn't exist. Is there a correction available for this (I didn't see anything in errata). Thanks!

Code:
            if(_id == -1) // Insert new item
            {
                myReview = new Review();
                myReview.CreateDateTime = DateTime.Now;
                myReview.UpdateDateTime = myReview.CreateDateTime;
                myEntities.Reviews.Add(myReview);
            }
This is the error I receive when I build the project:

Error 1 'System.Data.Objects.ObjectSet<PlanetWroxModel.Rev iew>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Objects.ObjectSet<PlanetWroxModel.Rev iew>' could be found (are you missing a using directive or an assembly reference?) C:\BegAPSNET\Site\Management\AddEditReviewHandCode d.aspx.cs 60 36 Site

Last edited by MeTP; January 7th, 2015 at 01:20 AM..
Reply With Quote
  #2 (permalink)  
Old January 7th, 2015, 01:22 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Found My Own Answer

The downloaded code sample has already fixed this problem. Should have checked there first.

Code:
      if (_id == -1) // Insert new item
      {
        myReview = new Review();
        myReview.CreateDateTime = DateTime.Now;
        myReview.UpdateDateTime = myReview.CreateDateTime;
        myEntities.AddToReviews(myReview);
      }
Reply With Quote
  #3 (permalink)  
Old January 7th, 2015, 04:49 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 not an error in the book. It looks you're using a mix of versions of the book and Visual Studio. Entity Framework changed quite a bit between versions where something like this

myEntities.AddToReviews(myReview);

has changed to this:

myEntities.Reviews.Add(myReview);

So, I think you're using either an older version of Visual Studio or EF than the book assumes.

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
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
Can’t add method to class in C#? arbab BOOK: Beginning C# 2005 Databases 0 September 29th, 2008 07:35 AM
How to add " " inside a method({ }) and XSLT 7 July 14th, 2008 03:27 AM
add method to control travlos Access VBA 2 August 4th, 2007 02:09 AM
add column if not exist Dj Kat MySQL 1 February 16th, 2006 01:57 PM



All times are GMT -4. The time now is 04:34 AM.


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