Exemplo n.º 1
0
		static void Main(string[] args)
		{
			List<SampleHarness> harnesses = new List<SampleHarness>();

			
			LinqSamples linqHarness = new LinqSamples();
			harnesses.Add(linqHarness);
						
			Application.EnableVisualStyles();
				
			using (SampleForm form = new SampleForm("HomeWork - Mihail Romanov", harnesses))
			{
				form.ShowDialog();
			}
		}
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            List <SampleHarness> harnesses = new List <SampleHarness>();

            LinqSamples linqHarness = new LinqSamples();

            harnesses.Add(linqHarness);

            LinqToSqlSamples linqToSqlHarness = new LinqToSqlSamples();

            harnesses.Add(linqToSqlHarness);

            Application.EnableVisualStyles();

            using (SampleForm form = new SampleForm("HomeWork", harnesses))
            {
                form.ShowDialog();
            }
        }
Exemplo n.º 3
0
        public void Linq003()
        {
            int[] arr = { 100, 1000, 10000, 100000 };

            foreach (var x in arr)
            {
                ObjectDumper.Write("");
                ObjectDumper.Write("");
                ObjectDumper.Write($"x is {x}");
                ObjectDumper.Write("");
                ObjectDumper.Write("");

                var result = this.dataSource.Customers
                             .Where(cust => cust.Orders.Any(order => order.Total > x))
                             .Select(cust => $"Customer {cust.CompanyName} have order with {cust.Orders.First(order => order.Total > x).Total} total");

                LinqSamples.Show(result);
            }
        }
Exemplo n.º 4
0
        public void Linq008()
        {
            const int min = 10;
            const int max = 100;

            var dict = new Dictionary <string, uint>
            {
                { "Low", 0 },
                { "Middle", 1 },
                { "High", 2 },
            };

            var result = this.dataSource.Products
                         .GroupBy(product => LinqSamples.GetRange(product, min, max),
                                  product => $"Name = {product.ProductName}, price is {product.UnitPrice.ToString(".##")}")
                         .OrderBy(kvp => dict[kvp.Key]);

            LinqSamples.Show(result);
        }
Exemplo n.º 5
0
        public void LinqQuery07()
        {
            decimal lowPrice  = 30;
            decimal highPrice = 80;
            var     products  = new LinqSamples().GetProductList();
            var     GroupProd = products.GroupBy(
                p =>
            {
                if (p.UnitPrice > highPrice)
                {
                    return("High");
                }
                if (p.UnitPrice > lowPrice)
                {
                    return("Middle");
                }
                return("Low");
            });

            ObjectDumper.Write(GroupProd, 5);
        }
Exemplo n.º 6
0
        public void Linq009()
        {
            var profitability = from customer in this.dataSource.Customers
                                group customer by customer.City
                                into groupped
                                select
                                new KeyValuePair <string, decimal>(groupped.Key,
                                                                   groupped.SelectMany(c => c.Orders).Average(o => o.Total));

            LinqSamples.WriteHeader("Profitability");
            LinqSamples.Show(profitability);

            var intensity = from customer in this.dataSource.Customers
                            group customer by customer.City
                            into groupped
                            select
                            new KeyValuePair <string, double>(groupped.Key, groupped.Average(customer => customer.Orders.Length));

            LinqSamples.WriteHeader("Intensity");
            LinqSamples.Show(intensity);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            List<SampleHarness> harnesses = new List<SampleHarness>();

            // LinqSamples:
            LinqSamples linqHarness = new LinqSamples();
            harnesses.Add(linqHarness);

            // Linq To SQL Samples:
            LinqToSqlSamples linqToSqlHarness = new LinqToSqlSamples();
            harnesses.Add(linqToSqlHarness);

            // LinqToXmlSamples:
            LinqToXmlSamples linqToXmlHarness = new LinqToXmlSamples();
            harnesses.Add(linqToXmlHarness);

            // DataSetLinqSamples:
            DataSetLinqSamples dsLinqSamples = new DataSetLinqSamples();
            harnesses.Add(dsLinqSamples);
            
            // XQueryUseCases:
            XQueryUseCases xqueryHarness = new XQueryUseCases();
            harnesses.Add(xqueryHarness);

            if (args.Length >= 1 && args[0] == "/runall") {
                foreach (SampleHarness harness in harnesses)
                {
                    harness.RunAllSamples();
                }
            }
            else {
                Application.EnableVisualStyles();
                
                using (SampleForm form = new SampleForm("LINQ Project Sample Query Explorer", harnesses))
                {
                    form.ShowDialog();
                }
            }
        }
Exemplo n.º 8
0
        public void LinqQuery09()
        {
            var customers = new LinqSamples().GetCustomerList();
            var res       = from c in customers
                            group c by c.CustomerID into custID
                            select new
            {
                Customer = custID.Key,
                custID   =
                    from y in custID
                    from o in y.Orders
                    group o by o.OrderDate.Year into oYear
                    select new
                {
                    Year  = oYear.Key,
                    oYear =
                        from m in oYear
                        group m by m.OrderDate.Month into oMonth
                        select new { Month = oMonth.Key, Sum = oMonth.Sum(order => order.Total) }
                }
            };

            ObjectDumper.Write(res, 5);
        }