Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using winwebapi.Models;

public ContactDetail Add(ContactDetail contact)
{

var addedContact = context.ContactDetails.Add(contact);
context.SaveChanges();
return addedContact;

}



hi here i am creating asp.net web api crud operations. can you see add function? it shows an error like follows

system.data.objects.objesctset<winwebapi.contactdetail>'does contain definition for Add and extension method 'Add' accepting a first argument type 'system.data.objects<winwebapi.contactdetail> could not be found (are you missing a using directive ro assembly reference?) i think i may miss namespace. so, pls help me why i got this error and how to solve?
Posted

1 solution

Try to use AddObject as mentioned below :

C#
context.ContactDetails.AddObject(contact);
 
Share this answer
 
v2
Comments
christhuxavier 12-Sep-13 7:35am    
hi thank you for reply. i did what you said follows
context.ContactDetails.AddObject(contact);
context.SaveChanges();
return context;

but in return statemetn shows error like : cannnot implicitly converttype'winwebapi.chdbentities to winwebapi.contactdetail'
CodeBlack 12-Sep-13 7:45am    
because your method expects contactdetail to be return not context.
retrun contact as mentioned below :

context.ContactDetails.AddObject(contact);
context.SaveChanges();
return contact;
christhuxavier 12-Sep-13 8:40am    
hi we are allocating contact to context which is object. we can only retrun context not contact. if i do above you said, i

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