MyShoppingCart.cs

Apr 27, 2011 at 4:18 PM

I've used the online video tutorial as well as the .html tutorial, and PDF tutorial. I keep getting stuck at the MyShoppingCart.cs creation stage. In the line "db.ShoppingCarts.AddObject(cartadd);" the method "AddObject" is not recognized. I can't figure out why. Any help is appreciated.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TailSpinPDFversion.Data_Access;
using TailSpinPDFversion;

namespace TailSpinPDFversion
{
    public partial class MyShoppingCart
    {
        public void AddItem(string cartID, int productID, int quantity)
        {
            using (CommerceEntities db = new CommerceEntities())
            {
                try
                {
                    var myItem =
                        (from c in db.ShoppingCarts where c.CartID == cartID && c.ProductID == productID select c).
                            FirstOrDefault();
                    if(myItem == null)
                    {
                        ShoppingCart cartadd = new ShoppingCart();
                        cartadd.CartID = cartID;
                        cartadd.Quantity = quantity;
                        cartadd.ProductID = productID;
                        cartadd.DateCreated = DateTime.Now;
                        db.ShoppingCarts.AddObject(cartadd);
                    }
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
        }
    }
}

Coordinator
Apr 27, 2011 at 4:24 PM

Did you compare your code to the finished project ?

Apr 27, 2011 at 5:13 PM

Up to that point (creating the AddItem method from the PDF tutorial) the code is the same expect for the name of the project. Below is the error that I get when building at that point.

 

'IdeaBlade.EntityModel.EntityQuery<TailSpinPDFversion.Data_Access.ShoppingCart>' does not contain a definition for 'AddObject' and no extension method 'AddObject' accepting a first argument of type 'IdeaBlade.EntityModel.EntityQuery<TailSpinPDFversion.Data_Access.ShoppingCart>' could be found (are you missing a using directive or an assembly reference?)    c:\users\mariond\documents\visual studio 2010\websites\TailSpinPDFversion\TailSpinPDFversion\Classes\MyShoppingCart.cs    28    42    TailSpinPDFversion

Apr 28, 2011 at 10:16 AM

Your class is missing a lot of declarations and logic, I would actually do what Joe said earlier.