public async Task <Kind> GetAsync(Guid id) { Kind kind = await _context.Kinds .FindAsync(id); if (kind == null) { return(null); } _context.Entry(kind).State = EntityState.Detached; return(kind); }
public async Task <Genre> GetAsync(Guid id) { Genre genre = await _context.Genres .FindAsync(id); if (genre == null) { return(null); } _context.Entry(genre).State = EntityState.Detached; return(genre); }
public async Task <Video> GetAsync(Guid id) { Video video = await _context.Videos .AsNoTracking() .Where(x => x.Id == id && !x.IsInactive) .Include(x => x.Genre) .Include(x => x.Kind).FirstOrDefaultAsync(); if (video == null) { return(null); } ; _context.Entry(video).State = EntityState.Detached; return(video); }
public void Update <TEntity>(TEntity item) where TEntity : class { try { var entity = _db.Find <TEntity>(item.GetType().GetProperty("Id").GetValue(item)); if (entity != null) { _db.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Detached; } _db.Set <TEntity>().Update(item); } catch { throw; } }
public void Update <TEntity>(TEntity entity) where TEntity : class { try { var entityObj = _dbContext.Find <TEntity>(entity.GetType().GetProperty("Id").GetValue(entity)); if (entityObj != null) { _dbContext.Entry(entityObj).State = //do this to be able to update the entity EntityState.Detached; //found entity isn’t tracked now } _dbContext.Update(entity); } catch (Exception) { throw; } }