Click here to Skip to main content
15,310,017 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.
Zaid Faridi 4-Jan-15 7:55am
   
Implementation was not needed in the tutorial. I copied the exact code.The only difference is that i am using vs 2010 and the tutorial uses vs 2013. Can that be a problem? Its true that i do not have much knowledge but i have to submit the project to my teachers anyway. If you could help out it would be much appreciated.
Richard MacCutchan 4-Jan-15 7:59am
   
Sorry, but I have no idea what that tutorial is about so cannot make much of a guess. All I can tell you is that it has something to do with the Products property of your GarageDBEntities class. I also assume that Products is (or should be) a collection of some sort.
Zaid Faridi 4-Jan-15 8:05am
   
its a webshop building tutorial by Michiel Wouters. here is the link
https://www.youtube.com/watch?v=BKujvivVFKI.
Product is one of the table in the GarageDB database.
Richard MacCutchan 4-Jan-15 8:23am
   
But the issue is with your GarageDBEntities class, not your database. As I said in an earlier post, if you really don't understand how your class should be built then you need to go back to your study notes for guidance.
Zaid Faridi 4-Jan-15 8:07am
   
Can you at least suggest a tutorial or a practice to better understand this problem?
Richard MacCutchan 4-Jan-15 8:20am
   
Sorry, but I don't know what problem you are trying to solve.

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