示例#1
0
 public Plant CreatePlant(Plant plant)
 {
     using (var database = new Core.Entity.SeedsEntities())
     {
         var entity = plant.ToEntity(database);
         entity.ID = database.Plant.Execute(MergeOption.NoTracking).Any() ? database.Plant.Execute(MergeOption.NoTracking).Max(p => p.ID) + 1 : 0;
         database.AddToPlant(entity);
         database.SaveChanges();
         var result = new Plant(database.Plant.Execute(MergeOption.NoTracking).Single(p => p.ID == entity.ID), true);
         result.UpdateParent();
         Cache.Instance.Plants[result.ID] = result;
         return result;
     }
 }