Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        public void add <anotherPocoTypePlaceholder>(params anotherPocoTypePlaceholder[] pocosToBeAdded)
            where anotherPocoTypePlaceholder : class, BookMeProject.iPoco

        {
            foreach (anotherPocoTypePlaceholder poco in pocosToBeAdded)
            {
                Console.WriteLine("\n\n\n current state of the Poco :- \n\n\n" + _context.Entry <anotherPocoTypePlaceholder>(poco).State);
                _context.Entry <anotherPocoTypePlaceholder>(poco).State = System.Data.Entity.EntityState.Added;
            }


            // Trying a Transaction Code here
            DbContextTransaction dbTransaction = _context.Database.BeginTransaction();

            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                dbTransaction.Rollback();
            }

            dbTransaction.Commit();
        }