public Position CreatePosition(Position position) { using (var database = new Core.Entity.SeedsEntities()) { var entity = position.ToEntity(database); entity.ID = database.Position.Execute(MergeOption.NoTracking).Any() ? database.Position.Execute(MergeOption.NoTracking).Max(p => p.ID) + 1 : 0; database.AddToPosition(entity); database.SaveChanges(); var newEntity = database.Position.Execute(MergeOption.NoTracking).Single(p => p.ID == entity.ID); var result = new Position(newEntity); Cache.Instance.Positions[result.ID] = result; return result; } }