Assuming that your userDb
is DbContext
(not an ObjectContext
) there are a few ways to achieve your goal.
You can do this in the following way:
var user = userDb.Users.FirstOrDefault(u => u.UserId == id);
if(user != null)
{
userDb.Users.Remove(user);
}
Or you could do this:
var user = userDb.Users.FirstOrDefault(u => u.UserId == id);
if(user != null)
{
userDb.Entry(user).State= EntityState.Deleted;
userDb.SaveChanges();
}