Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey!

Help me in getting out of these errors:
Error 2
'System.Data.Objects.ObjectSet<cruds.abc>' does not contain a definition for 'Add' and no extension method 'Add'

Error 3
'CRUDs.CRUDsEntities' does not contain a definition for 'Entry' and no extension method 'Entry'

Error 4
'System.Data.Objects.ObjectSet<cruds.abc>' does not contain a definition for 'Remove' and no extension method 'Remove'

THNKS! :)
Posted
Comments
Suvabrata Roy 8-Aug-14 3:32am    
Provide code where error occurred
Abhishek Jaiswall 8-Aug-14 4:50am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;

namespace CRUDs.Controllers
{
public class EmployeeController : Controller
{
private CRUDsEntities db = new CRUDsEntities();
//
// GET: /Employee/

public ActionResult Index()
{
return View(db.Employees.ToList());
}

//
// GET: /Employee/Details/5

public ActionResult Details(string id = null)
{
// Employee Emp = db.Employees.Find(id);
var Emp = (from E in db.Employees where E.EmployeeId == id select E);
if (Emp == null)
{
// return HttpNotFound();
}
return View(Emp);
}

//
// GET: /Employee/Create

public ActionResult Create()
{
return View();
}

//
// POST: /Employee/Create

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Employee Emp)
{
try
{
// TODO: Add insert logic here

if (ModelState.IsValid)
{
db.Employees.Add(Emp); // ObjectSet
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch
{
return View(Emp);
}
}

//
// GET: /Employee/Edit/5

public ActionResult Edit(string id = null)
{
// Employee Emp = db.Employees.Find(id);
var Emp = (from E in db.Employees where E.EmployeeId == id select E);
if (Emp == null)
{
// return HttpNotFound();
}
return View(Emp);
}

//
// POST: /Employee/Edit/5

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Employee Emp)
{
try
{
// TODO: Add update logic here

if (ModelState.IsValid)
{
db.Entry(Emp).State = EntityState.Modified; // ObjectSet
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch
{
return View(Emp);
}
}

//
// GET: /Employee/Delete/5

public ActionResult Delete(String id = null)
{
// Employee Emp = db.Employees.Find(id);
var Emp = (from E in db.Employees where E.EmployeeId == id select E);
if (Emp == null)
{
// return HttpNotFound();
}
return View(Emp);
}

//
// POST: /Employee/Delete/5

[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(String id)
{
try
{
// TODO: Add delete logic here

// Employee Emp = db.Employees.Find(id);
var Emp = (from E in db.Employees where E.EmployeeId == id select E);
db.Employees.Remove(Emp); // ObjectSet
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{ }
}

protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
Suvabrata Roy 8-Aug-14 5:00am    
Try to use using when you are using DataContext and please post code of CRUDsEntities problem resides there.

post your CRUDsEntityes problem is ther and also put your view
 
Share this answer
 
These operations don't work in MVC lower version (Below version 3). So try using these in MVC3 or above, they will work fine.
(These are autogenerated when you do select CRUD operations)

#HappyCoding!
 
Share this answer
 

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