Thursday 25 June 2015

Delete single / multiple row from Entity Framework 6.0 in C#

Delete single Row code example
ucontext.loginattempt.Remove(ucontext.loginattempt.SingleOrDefault(o => o.UserID== 1 ));
ucontext.SaveChanges();

or
var obj = new Loginattempt()
{
id=1
}
ucontext.loginattempt.Remove(obj);
ucontext.SaveChanges();



Delete multiple Rows code example
ucontext.loginattempt.RemoveRange(ucontext.loginattempt.Where(o => o.UserID == 1));
ucontext.SaveChanges();