public int AddTracker() { var index = Trackers .OrderBy(tr => tr.TrackerId) .Count() + 1; var tracker = new Tracker() { TrackerId = index, }; lock (lockObj) { Trackers.Add(tracker); SaveChanges(); } return(tracker.TrackerId); }