示例#1
0
 public MapNpcDTO Insert(MapNpcDTO npc)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             MapNpc entity = _mapper.Map <MapNpc>(npc);
             context.MapNpc.Add(entity);
             context.SaveChanges();
             return(_mapper.Map <MapNpcDTO>(entity));
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(null);
     }
 }
示例#2
0
 public void Insert(List <MapNpcDTO> npcs)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (MapNpcDTO Item in npcs)
             {
                 MapNpc entity = _mapper.Map <MapNpc>(Item);
                 context.MapNpc.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }