public ArquiteturaBaseContexto BuscarContexto() { if (contexto != null) { return(contexto); } contexto = new ArquiteturaBaseContexto(); return(contexto); }
public virtual async void AdicionarAsync(T entidade) { using (_contexto = new ArquiteturaBaseContexto()) { if (_contexto.Database.GetDbConnection().State != ConnectionState.Open) { await _contexto.Database.GetDbConnection().OpenAsync(); } _contexto.Set <T>().Add(entidade); await _contexto.SaveChangesAsync(); _contexto.Dispose(); } }
public virtual async void ExcluirAsync(T entidade) { using (_contexto = new ArquiteturaBaseContexto()) { if (_contexto.Database.GetDbConnection().State != ConnectionState.Open) { await _contexto.Database.GetDbConnection().OpenAsync(); } _contexto.Entry(entidade).State = EntityState.Deleted; await _contexto.SaveChangesAsync(); _contexto.Dispose(); } }
public virtual async Task <T> BuscarPorCodigoAsync(long id) { using (_contexto = new ArquiteturaBaseContexto()) { if (_contexto.Database.GetDbConnection().State != ConnectionState.Open) { await _contexto.Database.GetDbConnection().OpenAsync(); } DbSet <T> dbset = _contexto.Set <T>(); var obj = dbset.Find(id); _contexto.Dispose(); return(obj); } }
public virtual async Task <IEnumerable <T> > BuscarPorCriterioAsync(Expression <Func <T, bool> > where) { List <T> list; using (_contexto = new ArquiteturaBaseContexto()) { if (_contexto.Database.GetDbConnection().State != ConnectionState.Open) { await _contexto.Database.GetDbConnection().OpenAsync(); } DbSet <T> dbset = _contexto.Set <T>(); list = dbset.Where(where).ToListAsync().Result.ToList(); _contexto.Dispose(); } return(list); }
public virtual async Task <IEnumerable <T> > BuscarTodosAsync() { List <T> list; using (_contexto = new ArquiteturaBaseContexto()) { if (_contexto.Database.GetDbConnection().State != ConnectionState.Open) { await _contexto.Database.GetDbConnection().OpenAsync(); } DbSet <T> dbset = _contexto.Set <T>(); list = dbset.ToListAsync().Result.ToList(); _contexto.Dispose(); } return(list); }
public virtual async void ExcluirAsync(Expression <Func <T, bool> > where) { using (_contexto = new ArquiteturaBaseContexto()) { if (_contexto.Database.GetDbConnection().State != ConnectionState.Open) { await _contexto.Database.GetDbConnection().OpenAsync(); } var objetos = _entidade.Where(where).AsEnumerable(); foreach (var obj in objetos) { _contexto.Entry(obj).State = EntityState.Deleted; await _contexto.SaveChangesAsync(); } _contexto.Dispose(); } }