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); } }
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); } }