Sunday, June 2, 2019

Linq Delete with EntityState

1.
public ActionResult Delete(int id)
{
    using (var cont = new db_context())
    {
        var emp = new Employee()
        {
            emp_id = id
        };
        cont.Entry(emp).State = System.Data.Entity.EntityState.Deleted;
        cont.SaveChanges();
    }
    return RedirectToAction("index");
}

No comments:

Post a Comment

Linq Expression syntax for where condtion in linq

(Expression<Func<T, bool>> filter)