public void DeleteByBeaconId(int id) { using (var context = new BeaconContext()) { try { var buddies = context.Buddies.Where(x => x.BeaconId == id); buddies.ToList().ForEach(x => context.Entry(x).State = EntityState.Deleted); context.RemoveRange(buddies); context.SaveChanges(); } catch { throw; } } }