Wrox Programmer Forums
|
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 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
 
Old January 6th, 2015, 06:34 PM
Registered User
 
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..
 
Old January 7th, 2015, 01:22 AM
Registered User
 
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);
      }
 
Old January 7th, 2015, 04:49 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.