public ReproductionStep CreateReproductionStep(ReproductionStep reproductionStep) { using (var database = new Core.Entity.SeedsEntities()) { var entity = reproductionStep.ToEntity(database); entity.ID = database.ReproductionStep.Execute(MergeOption.NoTracking).Any() ? database.ReproductionStep.Execute(MergeOption.NoTracking).Max(rs => rs.ID) + 1 : 0; database.AddToReproductionStep(entity); database.SaveChanges(); var newEntity = database.ReproductionStep.Execute(MergeOption.NoTracking).Single(rs => rs.ID == entity.ID); var result = new ReproductionStep(newEntity); var plant = Cache.Instance.Plants[newEntity.PlantID]; result.Plant = plant; plant.ReproductionSteps[result.ID] = result; return result; } }