Using the ASP.NET Web API DELETE method with entity framework to pass the student id and if the id exists in the table delete the record. When I try to test it I get the following error message
"System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName) System.Data.Entity.DbContext.Entry[TEntity](TEntity entity)"
public class StudentController : ApiController
{
[HttpDelete]
[Route("student/DeleteStudent/{id}")]
public IHttpActionResult DeleteStudent(string id)
{
using (var sd = new SchoolDBEntities())
{
var student = sd.Students
.Where(s => s.StudentID == id)
.FirstOrDefault();
sd.Entry(student).State = System.Data.Entity.EntityState.Deleted;
sd.SaveChanges();
}
if (id == null)
return BadRequest("Not a valid student id");
return Ok();
}
}