Click here to Skip to main content
15,883,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am building a webshop using VS 2010 and sql server management studios. It is the exact code i saw in a tutorial but the Find() and Add() functions are giving errors. Please help.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GarageDBModel;

/// <summary>
/// Summary description for ProductModel
/// </summary>
public class ProductModel
{
    public string InsertProduct(Product product)
    {
        try
        {
            GarageDBEntities db = new GarageDBEntities();
            db.Products.Add(product);
            db.SaveChanges();

            return product.Name + "was succesfuly Inserted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }

    public string UpdateProduct(int id, Product product)
    {
        try
        {
            GarageDBEntities db = new GarageDBEntities();
            Product p = db.Products.Find(id);
        }
        catch(Exception e)
        {
            return "Error:" + e;
        }
    }



Error   4   'System.Data.Objects.ObjectSet<GarageDBModel.Product>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Objects.ObjectSet<GarageDBModel.Product>' could be found (are you missing a using directive or an assembly reference?) C:\Users\Zaid\Documents\Visual Studio 2010\WebSites\Garagemanager\App_Code\Models\ProductModel.cs   18  25  C:\...\Garagemanager\


Error   5   'System.Data.Objects.ObjectSet<GarageDBModel.Product>' does not contain a definition for 'Find' and no extension method 'Find' accepting a first argument of type 'System.Data.Objects.ObjectSet<GarageDBModel.Product>' could be found (are you missing a using directive or an assembly reference?)   C:\Users\Zaid\Documents\Visual Studio 2010\WebSites\Garagemanager\App_Code\Models\ProductModel.cs   34  37  C:\...\Garagemanager\
Posted
Updated 3-Jan-15 21:15pm
v2
Comments
George Jonsson 4-Jan-15 3:17am    
What tutorial are you referring to?
How is the class GarageDBEntities defined?
Zaid Faridi 4-Jan-15 6:40am    
its a tutorial by Michiel Wouters. here is the link
https://www.youtube.com/watch?v=BKujvivVFKI
Richard MacCutchan 4-Jan-15 3:38am    
The messages are telling you what is wrong; you need implementations of both those methods in your clas.
Zaid Faridi 4-Jan-15 6:40am    
How should i do that?
Richard MacCutchan 4-Jan-15 7:31am    
Add implementations fopr the methods; how else? If you do not understand such basic parts of the language you need to go back to your study notes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900