public async Task CreateAsync(YayYoApplication yayYoApplication) { try { _dbSet.Add(yayYoApplication); await _context.SaveChangesAsync(); } catch (Exception ex) { LogError("There is error while updating YayYoApplication: " + ex.Message, ex); } }
public void Create(YayYoApplication yayYoApplication) { try { _dbSet.Add(yayYoApplication); _context.SaveChanges(); } catch (Exception ex) { LogError("There is error while updating YayYoApplication: " + ex.Message, ex); } }
public async Task DeleteAsync(YayYoApplication yayYoApplication) { try { _cacheManager.Remove(String.Format(KeyForCacheYayYo, yayYoApplication.Id)); _context.Database.ExecuteSqlCommand("DELETE YayYoApplication WHERE Id = @p0", yayYoApplication.Id); await _context.SaveChangesAsync(); } catch (Exception ex) { LogError("There is error while updating data: " + ex.Message, ex); } }
public async Task UpdateAsync(YayYoApplication yayYoApplication) { try { _cacheManager.Remove(String.Format(KeyForCacheYayYo, yayYoApplication.Id)); //ref:http://patrickdesjardins.com/blog/entity-framework-ef-modifying-an-instance-that-is-already-in-the-context //A way to do it is to navigate inside the local of the DbSet to see if this one is there. If the entity is present, than you detach var local = _context.Set <YayYoApplication>() .Local .FirstOrDefault(f => f.Id == yayYoApplication.Id); if (local != null) { _context.Entry(local).State = EntityState.Detached; } _context.Entry(yayYoApplication).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { LogError("There is error while updating YayYoApplication: " + ex.Message, ex); } }
public void Update(YayYoApplication yayYoApplication) { try { _cacheManager.Remove(String.Format(KeyForCacheYayYo, yayYoApplication.Id)); //ref:http://patrickdesjardins.com/blog/entity-framework-ef-modifying-an-instance-that-is-already-in-the-context //A way to do it is to navigate inside the local of the DbSet to see if this one is there. If the entity is present, than you detach var local = _context.Set <YayYoApplication>() .Local .FirstOrDefault(f => f.Id == yayYoApplication.Id); if (local != null) { _context.Entry(local).State = EntityState.Detached; } _context.Entry(yayYoApplication).State = EntityState.Modified; _context.SaveChanges(); } catch (Exception ex) { //Log the error (uncomment dex variable name and add a line here to write a log. //Trace.TraceError("There is error while updating data: " + dex.InnerException); LogError("There is error while updating YayYoApplication: " + ex.Message, ex); } }