public void Delete(int id) { var existingUser = _context.Users.SingleOrDefault(u => u.Id == id); if (existingUser == null) { return; } var userDevices = _context.Devices.Where(d => d.UserId == id).ToList(); _context.RemoveRange(userDevices); _context.Remove(existingUser); _context.SaveChanges(); }