public async Task <IEnumerable <Extrato> > GetByQueryAsync(string query) { using (var context = new WpFinanceiroContext()) { var result = await context.Set <Extrato>().FromSql(query).ToListAsync(); return(result); } }
/// <summary> /// Remove um objeto da base dados /// </summary> /// <param name="items">Item Operantante pode se passar um unique ou lista de objetos a ser salvo</param> public virtual void Remove(params T[] items) { var context = new WpFinanceiroContext(); foreach (T item in items) { context.Entry(item).State = EntityState.Deleted; } context.SaveChanges(); }
/// <summary> /// Adiciona um item na base de dados /// </summary> /// <param name="items">Baseado na classe operante</param> public virtual IEnumerable <T> Add(params T[] items) { var context = new WpFinanceiroContext(); foreach (var item in items) { context.Entry(item).State = EntityState.Added; } context.SaveChanges(); return(items); }
/// <summary> /// Busca todos itens salvo na base /// </summary> /// <param name="navigationProperties">Classe operante</param> /// <returns>Lista baseada no tipo passado</returns> public virtual IList <T> GetAll() { List <T> list; var context = new WpFinanceiroContext(); IQueryable <T> dbQuery = context.Set <T>(); list = dbQuery .ToList <T>(); return(list); }
/// <summary> /// /// </summary> /// <param name="where"></param> /// <param name="navigationProperties"></param> /// <returns></returns> public virtual T GetSingle(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties) { T item = null; var context = new WpFinanceiroContext(); IQueryable <T> dbQuery = context.Set <T>(); //Apply eager loading foreach (Expression <Func <T, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include <T, object>(navigationProperty); } item = dbQuery .AsNoTracking() //Don't track any changes for the selected item .FirstOrDefault(where); //Apply where clause return(item); }
/// <summary> /// Usado para pegar todos utilizando Lambda Expression /// </summary> /// <param name="where">Sintaxe where para selecionar uma clausula</param> /// <param name="navigationProperties">Classe Operante</param> /// <returns>Lista filtrada</returns> public virtual IList <T> GetList(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties) { List <T> list = new List <T>(); var context = new WpFinanceiroContext(); IQueryable <T> dbQuery = context.Set <T>().AsQueryable(); var query = context.Set <T>().AsQueryable(); //Apply eager loading foreach (Expression <Func <T, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include <T, object>(navigationProperty); } list = dbQuery .AsNoTracking() .Where(where) .ToList <T>(); return(list); }