Link to home
Start Free TrialLog in
Avatar of mustish1
mustish1

asked on

Entity framework

VS 2019
Can you please help me with this error?
User generated imageUser generated imageusing System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using Scheduling.Models;

namespace Scheduling.Controllers
{
public class SchedulingController : Controller
{
private SchedulingContext db = new SchedulingContext();

// GET: Scheduling
public ActionResult Index()
{
List<Bks_DWH_TrainingProgramsBasicData> trainingPrograms = db.Bks_DWH_TrainingProgramsBasicData.ToList();
return View(trainingPrograms);
}

// GET: Scheduling/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}

Bks_DWH_TrainingProgramsBasicData trainingProgram = db.Bks_DWH_TrainingProgramsBasicData.Find(id);
if (trainingProgram == null)
{
return HttpNotFound();
}

return View(trainingProgram);
}

// GET: Scheduling/Create
public ActionResult Create()
{
return View();
}

// POST: Scheduling/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Bks_DWH_TrainingProgramsBasicData trainingProgram)
{
if (ModelState.IsValid)
{
db.Bks_DWH_TrainingProgramsBasicData.Add(trainingProgram);
db.SaveChanges();
return RedirectToAction("Index");
}

return View(trainingProgram);
}

// GET: Scheduling/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}

Bks_DWH_TrainingProgramsBasicData trainingProgram = db.Bks_DWH_TrainingProgramsBasicData.Find(id);
if (trainingProgram == null)
{
return HttpNotFound();
}

return View(trainingProgram);
}

// POST: Scheduling/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Bks_DWH_TrainingProgramsBasicData trainingProgram)
{
if (ModelState.IsValid)
{
db.Entry(trainingProgram).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}

return View(trainingProgram);
}

// GET: Scheduling/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}

Bks_DWH_TrainingProgramsBasicData trainingProgram = db.Bks_DWH_TrainingProgramsBasicData.Find(id);
if (trainingProgram == null)
{
return HttpNotFound();
}

return View(trainingProgram);
}

// POST: Scheduling/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Bks_DWH_TrainingProgramsBasicData trainingProgram = db.Bks_DWH_TrainingProgramsBasicData.Find(id);
db.Bks_DWH_TrainingProgramsBasicData.Remove(trainingProgram);
db.SaveChanges();
return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}

base.Dispose(disposing);
}
}
}

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

You don't seem to be including EntityState:
The entity state represented by an enum System.Data.Entity.EntityState in EF 6 and Microsoft.EntityFrameworkCore.EntityState in EF Core with the following values:

Reference:
https://www.entityframeworktutorial.net/basics/entity-states.aspx



ASKER CERTIFIED SOLUTION
Avatar of Jonathan D.
Jonathan D.
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial