Exemplo n.º 1
0
        // This returns the Pocos with all its navigation Properties ----> without a predicate or a Select criterion
        public List <anotherPocoTypePlaceholder> GetAll <anotherPocoTypePlaceholder>(params Expression <Func <anotherPocoTypePlaceholder, object> >[] navigationPropertyListPathObject)
            where anotherPocoTypePlaceholder : class, iPoco
        {
            IQueryable <anotherPocoTypePlaceholder> queryBuilder = _context.Set <anotherPocoTypePlaceholder>();

            foreach (Expression <Func <anotherPocoTypePlaceholder, object> > navigationPropertyPathObject in navigationPropertyListPathObject)
            {
                queryBuilder = queryBuilder
                               .Include <anotherPocoTypePlaceholder, object>(navigationPropertyPathObject);
            }

            List <anotherPocoTypePlaceholder> pocoList = queryBuilder.ToList <anotherPocoTypePlaceholder>();



            if (pocoList == null)
            {
                return(null);
            }
            else
            {
                // to see the DBContext tracking state of Poco
                foreach (anotherPocoTypePlaceholder poco in pocoList)
                {
                    Console.WriteLine("\n\n\n current state of the Poco :- \n\n\n" + _context.Entry <anotherPocoTypePlaceholder>(poco).State);
                }

                return(pocoList);
            }
        }
Exemplo n.º 2
0
        // This will not work for entities with navigation Properties. -- FIX this
        public void delete <anotherPocoTypePlaceholder>(Expression <Func <anotherPocoTypePlaceholder, bool> > wherePredicate)
            where anotherPocoTypePlaceholder : class, iPoco
        {
            IEnumerable <anotherPocoTypePlaceholder> pocosTobeDeleted = _context.Set <anotherPocoTypePlaceholder>().Where(wherePredicate);

            foreach (anotherPocoTypePlaceholder poco in pocosTobeDeleted)
            {
                Console.WriteLine("\n\n\n current state of the Poco :- \n\n\n" + _context.Entry <anotherPocoTypePlaceholder>(poco).State);
                _context.Entry <anotherPocoTypePlaceholder>(poco).State = EntityState.Deleted;
            }
            _context.SaveChanges();
        }
Exemplo n.º 3
0
        // this will not work for entities with navigation Properties.
        // FIx this
        public void delete <anotherPocoTypePlaceholder> (Expression <Func <anotherPocoTypePlaceholder, bool> > wherePredicate)
            where anotherPocoTypePlaceholder : class, iPoco
        {
            IEnumerable <anotherPocoTypePlaceholder> pocosTobeDeleted = _context.Set <anotherPocoTypePlaceholder>().Where(wherePredicate);

            foreach (anotherPocoTypePlaceholder poco in pocosTobeDeleted)
            {
                if (poco != null)
                {
                    Console.WriteLine("\n\n\n current state of the Poco :- \n\n\n" + _context.Entry <anotherPocoTypePlaceholder>(poco).State);
                    _context.Entry <anotherPocoTypePlaceholder>(poco).State = EntityState.Deleted;
                }
                else
                {
                    throw new Exception("EF Implementation Layer:- A Null Record was Found");
                }
            }
            _context.SaveChanges();
        }