Beispiel #1
0
        static void Main(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <AdventureWorksContext>();

            optionsBuilder.UseSqlServer(Settings.Adventure);
            AdventureWorksContext context = new AdventureWorksContext(optionsBuilder.Options);

            new IntroAnimation().Play();

            History history = new History(context);

            history.Presenter();

            LanguageSupport language = new LanguageSupport(context);

            language.Presenter();

            QueryOperators queryOperators = new QueryOperators();

            queryOperators.Presenter();

            DeferredExecution deferred = new DeferredExecution(context);

            deferred.Presenter();

            Performance perf = new Performance(context);

            perf.PerformancePresenter();

            Console.ReadLine();
        }
        /// <summary>
        /// Does not throw
        ///
        /// The operation cannot be completed because the DbContext has been disposed.
        /// As unlike the above code sample a live DbContext is still available.
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetProductsIQueryableWithoutExceptionButton_Click(object sender, EventArgs e)
        {
            var ops = new DeferredExecution();

            List <Product> results = ops.GetProductsIQueryable2()
                                     .ToList();
        }
Beispiel #3
0
 private static void ExampleDeferredExecution()
 {
     Console.WriteLine("Deferred Execution");
     Console.WriteLine("Antes de Materializar");
     DeferredExecution.AlteradoAntesDeMaterializarAQuery();
     Console.WriteLine("Depois de Materializar");
     DeferredExecution.AlteradoDepoisDeMaterializarAQuery();
 }
Beispiel #4
0
        public void Reverse2Test()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Reverse(enumerable),
                DeferredExecution.CompiledReverseGenerator(enumerable));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Reverse(enumerable),
                DeferredExecution.CompiledReverseGenerator(enumerable));
        }
        /// <summary>
        /// In the last example above an exception is thrown when executed
        /// while this code example will not throw an exception because .ToList
        /// executed the query unlike GetProductsIQueryable2 method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetProductsToListWithoutExceptionButton_Click(object sender, EventArgs e)
        {
            var ops = new DeferredExecution();

            try
            {
                List <Product> results = ops.GetProductsAsList()
                                         .ToList();

                MessageBox.Show(results.Count.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show($"The following was an expected exception\n{ex.Message}");
            }
        }
        /// <summary>
        /// Throw exception
        /// The operation cannot be completed because the DbContext has been disposed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetProductsIQueryableWithExceptionButton_Click(object sender, EventArgs e)
        {
            var ops = new DeferredExecution();

            try
            {
                List <List <Product> > results = ops.GetProductsIQueryable1()
                                                 .Cast <List <Product> >()
                                                 .ToList();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show($"The following was an expected exception\n{ex.Message}");
            }
        }
Beispiel #7
0
        private static void DemoPart1()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("1). Filtering: Onderstaande functies is een filtering van de 15 producten.");
            WhiteLine();
            Filtering.Intro();
            WhiteLine();
            Filtering.MethodHighTierProducts();
            Breaker();
            Filtering.QueryHighTierProducts();
            Breaker();

            Console.WriteLine("2). Ordering: Onderstaande functies is een ordering van 15 orders.");
            WhiteLine();
            Ordering.Intro();
            WhiteLine();
            Ordering.MethodByTotalPrice();
            Breaker();
            Ordering.QueryByTotalPrice();
            Breaker();

            Console.WriteLine("3). Projection: Onderstaande functies is een projectie van 15 customers.");
            WhiteLine();
            Projection.SelectIntro();
            WhiteLine();
            Projection.MethodSelectCustomerName();
            Breaker();
            Projection.QuerySelectCustomerName();
            Breaker();

            Projection.SelectManyIntro();
            WhiteLine();
            Projection.MethodSelectManyProductIds();
            Breaker();
            Projection.QuerySelectManyProductIds();
            Breaker();

            Console.WriteLine("4). Joining: Onderstaande functies is een joining van 15 producten, orders en customers.");
            WhiteLine();
            Joining.InnerJoinIntro();
            WhiteLine();
            Joining.MethodInnerCustomerOrderProducts();
            Breaker();
            Joining.QueryInnerCustomerOrderProducts();
            Breaker();

            Joining.OuterJoinIntro();
            WhiteLine();
            Joining.MethodOuterCustomerOrderProducts();
            Breaker();
            Joining.QueryOuterCustomerOrderProducts();
            Breaker();

            Console.WriteLine("5). Grouping: Onderstaande functies is een groupering van 15 orders.");
            WhiteLine();
            Grouping.Intro();
            WhiteLine();
            Grouping.MethodByShippingCost();
            Breaker();
            Grouping.QueryByShippingCost();
            Breaker();

            Console.WriteLine("6). Aggregates: Onderstaande functies zijn aggregates van 15 producten.");
            WhiteLine();
            Aggregates.CountIntro();
            WhiteLine();
            Aggregates.MethodCountByPrice();
            Breaker();
            Aggregates.QueryCountByPrice();
            Breaker();

            Aggregates.MinIntro();
            WhiteLine();
            Aggregates.MethodMinPrice();
            Breaker();
            Aggregates.QueryMinPrice();
            Breaker();

            Aggregates.MaxIntro();
            WhiteLine();
            Aggregates.MethodMaxPrice();
            Breaker();
            Aggregates.QueryMaxPrice();
            Breaker();

            Aggregates.SumIntro();
            WhiteLine();
            Aggregates.MethodSumPrice();
            Breaker();
            Aggregates.QuerySumPrice();
            Breaker();

            Aggregates.AverageIntro();
            WhiteLine();
            Aggregates.MethodAveragePrice();
            Breaker();
            Aggregates.QueryAveragePrice();
            Breaker();

            Console.WriteLine("7). Partitioning: Onderstaande functies zijn partitioning van 15 customers.");
            WhiteLine();
            Partitioning.TakeSkipIntro();
            WhiteLine();
            Partitioning.TakeFive();
            Breaker();
            Partitioning.SkipFive();
            Breaker();

            Partitioning.FirstFirstOrDefaultIntro();
            WhiteLine();
            Partitioning.FirstOnName();
            Breaker();
            Partitioning.FirstOnNameException();
            Breaker();
            Partitioning.FirstOrDefaultOnName();
            Breaker();

            Partitioning.DistinctIntro();
            WhiteLine();
            Partitioning.DistinctCustomers();
            Breaker();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("8). Deferred Execution: Onderstaande functies is het uitvoeren van deferred execution.");
            WhiteLine();
            DeferredExecution.Demo();
            Breaker();
        }
Beispiel #8
0
 public void QueryTest()
 {
     DeferredExecution.ForEachWhereAndSelect();
     DeferredExecution.ForEachSelectAndReverse();
 }
 public void QueryTest()
 {
     DeferredExecution.CallWhereAndSelect();
     DeferredExecution.CallSelectAndReverse();
 }
Beispiel #10
0
        public void ShowExample_Click(object sender, EventArgs e)
        {
            Form form = null;

            switch (((Button)sender).Name)
            {
            // LINQ Dynamic | Restriction Operators
            case "uiROWhere":
                form = new Where();
                break;

            // LINQ Dynamic | Projection Operators
            case "uiPOSelect":
                form = new Select();
                break;

            case "uiPOSelectMany":
                form = new SelectMany();
                break;

            // LINQ Dynamic | Aggregate Operators
            case "uiAOMin":
                form = new Min();
                break;

            case "uiAOMax":
                form = new Max();
                break;

            case "uiAOSum":
                form = new Sum();
                break;

            case "uiAOCount":
                form = new Count();
                break;

            case "uiAOAverage":
                form = new Average();
                break;

            case "uiAOAggregate":
                form = new Aggregate();
                break;

            // LINQ Dynamic | Query Execution
            case "uiQEDeferredExecution":
                form = new DeferredExecution();
                break;

            case "uiQEQueryReuse":
                form = new QueryReuse();
                break;

            case "uiQEImmediateExecution":
                form = new ImmediateExecution();
                break;


            // LINQ Dynamic |  Join Operators
            case "uiJOCrossJoin":
                form = new CrossJoin();
                break;

            case "uiJOGroupJoin":
                form = new GroupJoin();
                break;

            case "uiJOCrossWithGroupJoin":
                form = new CrossJoinwithGroupJoin();
                break;

            case "uiJOLeftOuterJoin":
                form = new LeftOuterJoin();
                break;

            // LINQ Dynamic |    Set Operators
            case "uiSODistinct":
                form = new Distinct();
                break;

            case "uiSOExcept":
                form = new Except();
                break;

            case "uiSOIntersect":
                form = new Intersect();
                break;

            case "uiSOUnion":
                form = new Union();
                break;

            // LINQ Dynamic |    Element Operators
            case "uiEOElementAt":
                form = new ElementAt();
                break;

            case "uiEOFirst":
                form = new First();
                break;

            case "uiEOFirstDefault":
                form = new FirstOrDefault();
                break;

            // LINQ Dynamic |    Custom Sequence Operators
            case "uiCSOCombine":
                form = new Combine();
                break;

            // LINQ Dynamic |    Quantifiers
            case "uiQuantifiersAll":
                form = new All();
                break;

            case "uiQuantifiersAny":
                form = new Any();
                break;

            // LINQ Dynamic |    Grouping Operators
            case "uiGOGroupBy":
                form = new GroupBy();
                break;

            // LINQ Dynamic |    Miscellaneous Operators
            case "uiMOConcat":
                form = new Concat();
                break;

            case "uiMOEqualAll":
                form = new EqualAll();
                break;


            // LINQ Dynamic |    Generation Operators
            case "uiGORepeat":
                form = new Repeat();
                break;

            case "uiGORange":
                form = new Range();
                break;


            // LINQ Dynamic |    Ordering Operators
            case "uiOOOrderBy":
                form = new OrderBy();
                break;

            case "uiOOThenBy":
                form = new ThenBy();
                break;

            case "uiOOThenByDescending":
                form = new ThenByDescending();
                break;

            case "uiOOOrderByDescending":
                form = new OrderByDescending();
                break;

            case "uiOOReverse":
                form = new Reverse();
                break;

            // LINQ Dynamic |    Conversion Operators
            case "uiCOOfType":
                form = new OfType();
                break;

            case "uiCOToArray":
                form = new ToArray();
                break;

            case "uiCOToDictionary":
                form = new ToDictionary();
                break;

            case "uiCOToList":
                form = new ToList();
                break;


            // LINQ Dynamic |    Partitioning Operators
            case "uiPOTake":
                form = new Take();
                break;

            case "uiPOTakeWhile":
                form = new TakeWhile();
                break;

            case "uiPOSkip":
                form = new Skip();
                break;

            case "uiPOSkipWhile":
                form = new SkipWhile();
                break;
            }

            form.StartPosition = FormStartPosition.CenterParent;
            form.ShowDialog();
        }