Exemplo n.º 1
0
        /// <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 WpQrCodeContext();

            foreach (T item in items)
            {
                context.Entry(item).State = EntityState.Deleted;
            }
            context.SaveChanges();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adiciona um item na base de dados
        /// </summary>
        /// <param name="items">Baseado na classe operante</param>
        public virtual int Add(params T[] items)
        {
            var context = new WpQrCodeContext();

            var item = items.FirstOrDefault();

            context.Entry(item).State = EntityState.Added;
            context.SaveChanges();

            return((item as dynamic).ID);
        }
Exemplo n.º 3
0
        /// <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 WpQrCodeContext();

            IQueryable <T> dbQuery = context.Set <T>();


            list = dbQuery
                   .ToList <T>();

            return(list);
        }
Exemplo n.º 4
0
        /// <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 WpQrCodeContext();
            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);
        }
Exemplo n.º 5
0
        /// <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 WpQrCodeContext();
            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);
        }