示例#1
0
        static void TestAdvWorks()
        {
            var conn = _config.GetConnectionString("AdvWorks");

            using var db = new AdventureWorks2017Context(conn);
            var query = db.Customers
                        .Include(x => x.Person)
                        .Include(x => x.SalesOrderHeaders)
                        .ThenInclude(x => x.SalesOrderDetails)
                        .Where(x => x.Person != null)
                        .Skip(100)
                        .Take(50)
            ;

            foreach (var c in query.ToList())
            {
                Console.WriteLine($"Customer: {c.AccountNumber}");
                Console.WriteLine($"  Person: {c.Person.FirstName} {c.Person.LastName}");
                foreach (var h in c.SalesOrderHeaders)
                {
                    Console.WriteLine($"  Order Status: {h.Status}");
                    Console.WriteLine($"   Order Total: {h.TotalDue}");
                    foreach (var d in h.SalesOrderDetails)
                    {
                        Console.WriteLine($"    Detail: {d.ProductID}");
                    }
                }
            }
        }
示例#2
0
        public static void Execute()
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            using var context = new AdventureWorks2017Context();
            var query = context.ProductInventory.OrderBy(pi => pi.Shelf)
                        .Select(pi => pi);


            foreach (var product in query)
            {
                Console.WriteLine("{0}", product.Shelf);
            }

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            var ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:00}";

            //; is for my shell script, which outputs to a csv
            Console.WriteLine("RunTime " + elapsedTime + ";");
        }
示例#3
0
        public static void Execute()
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            using var context = new AdventureWorks2017Context();
            var query = context.Address.GroupBy(address => address.City)
                        .Select(group => new
            {
                Count = group.Count(),
                City  = group.Key
            });

            foreach (var addressGroup in query)
            {
                Console.WriteLine("{0} {1}", addressGroup.Count, addressGroup.City);
            }

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            var ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:00}";

            //; is for my shell script, which outputs to a csv
            Console.WriteLine("RunTime " + elapsedTime + ";");
        }
示例#4
0
        public static void Execute()
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            using var context = new AdventureWorks2017Context();
            var query = context.Product.Where(product =>
                                              product.SellStartDate > new DateTime(2007, 1, 1) &&
                                              EF.Functions.Like(product.ProductNumber, "FW%"))
                        .Select(product => product.Name);


            foreach (var product in query)
            {
                Console.WriteLine("{0}", product);
            }

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            var ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:00}";

            //; is for my shell script, which outputs to a csv
            Console.WriteLine("RunTime " + elapsedTime + ";");
        }
示例#5
0
        static void Main(string[] args)
        {
            var db = new AdventureWorks2017Context();

            foreach (var p in db.Person.ToList())
            {
                Console.WriteLine($"{p.FirstName} {p.LastName}");
            }
        }
        static void Main(string[] args)
        {
            AdventureWorks2017Context context = new AdventureWorks2017Context();

            var product = (from p in context.Products.AsParallel().AsOrdered() // karisik degil, veritabani sirasinda verir. ama sonrasinda for each kullanmak daha mantikli.
                           where p.ListPrice > 10M
                           select p).Take(10);

            product.ForAll(x =>
            {
                Console.WriteLine(x.Name);
            });
        }
        static void Main(string[] args)
        {
            //var array = Enumerable.Range(1, 100).ToList();

            //var arrayList = array.AsParallel().Where(x => x % 2 == 0);

            //arrayList.ToList().ForEach(x =>
            //{
            //    Thread.Sleep(1000);
            //    Console.WriteLine(x);
            //});

            // PLINQ - ForAll
            //arrayList.ForAll(x =>
            //{
            //    Thread.Sleep(1000);
            //    Console.WriteLine(x);
            //});


            /* ---------------------------------- */

            AdventureWorks2017Context context = new AdventureWorks2017Context();

            // If we want to query over an existing array
            //var product = (from p in context.Product.AsParallel()
            //               where p.ListPrice > 10M
            //               select p).Take(10);

            //product.ForAll(x =>
            //{
            //    Console.WriteLine(x.Name);
            //});

            context.Product.AsParallel().ForAll(p =>
            {
                GetLog(p);
            });

            // AsOrdered - maintains the order in the array

            //context.Product.AsParallel().AsOrdered().Where(p => p.ListPrice > 10M).ToList().ForEach(x =>
            //{
            //    Console.WriteLine($"{x.Name} - {x.ListPrice}");
            //});
        }
        public JsonResult GetData([DataSourceRequest] DataSourceRequest request, bool custom = false)
        {
            using (var db = new AdventureWorks2017Context())
            {
                IQueryable <OrderDetailViewModel> orders =
                    db.SalesOrderDetail
                    .Include(o => o.SalesOrder)
                    .Include(o => o.SpecialOfferProduct)
                    .ThenInclude(p => p.Product)
                    .Select(o => new OrderDetailViewModel
                {
                    OrderDetailID       = o.SalesOrderDetailId,
                    OrderTrackingNumber = o.CarrierTrackingNumber,
                    OrderDate           = o.SalesOrder.OrderDate,
                    AccountNumber       = o.SalesOrder.AccountNumber,
                    LineTotal           = o.LineTotal,
                    OrderQty            = o.OrderQty,
                    UnitPrice           = o.UnitPrice,
                    ProductName         = o.SpecialOfferProduct.Product.Name,
                    SpecialOfferID      = o.SpecialOfferId
                });


                var watch = Stopwatch.StartNew();

                var result = custom ? orders.ToCustomDataSourceResul(request) : orders.ToDataSourceResult(request);


                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;

                Debug.WriteLine("============================================================");
                Debug.WriteLine(" > HomeController: " + elapsedMs + " ms");
                Debug.WriteLine("============================================================");

                var t = result.Data;

                return(Json(result));
            }
        }
示例#9
0
        public static void Execute()
        {
            var stopWatch = new Stopwatch();
            stopWatch.Start();

            var context = new AdventureWorks2017Context();
            var query = context.Product.Where(p => context.ProductVendor.Any(
                pv => pv.ProductId.Equals(p.ProductId) && pv.MinOrderQty > 5));
                
                
            foreach (var product in query)
            {
                Console.WriteLine("{0}", product.Name);
            }

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            var ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:00}";
            //; is for my shell script, which outputs to a csv 
            Console.WriteLine("RunTime " + elapsedTime + ";");
        }
示例#10
0
 public EmailAddressController(AdventureWorks2017Context AdventureWorks2017Context)
 {
     _db = AdventureWorks2017Context;
 }
示例#11
0
 public AddressesController(AdventureWorks2017Context context)
 {
     _context = context;
 }
 public CustomerService(AdventureWorks2017Context context, IMapper mapper, IDataTableService dataTableService)
 {
     _context          = context;
     _mapper           = mapper;
     _dataTableService = dataTableService;
 }
示例#13
0
 public PersonRepository(AdventureWorks2017Context context)
 {
     _context = context;
 }
示例#14
0
 public EmployeesController(AdventureWorks2017Context context)
 {
     _context = context;
 }
 public ProductRepository(AdventureWorks2017Context context)
 {
     _context = context;
 }
示例#16
0
 public Repository(AdventureWorks2017Context context)
 {
     this.context = context;
 }
 public ProductController(AdventureWorks2017Context context)
 {
     _context = context;
 }
示例#18
0
 public ProductController(AdventureWorks2017Context context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
示例#19
0
 protected GenericRepository(AdventureWorks2017Context dbContext)
 {
     DbContext = dbContext;
 }
示例#20
0
 public ProductController(AdventureWorks2017Context context, IMapper mapper, ILogger <ProductController> logger)
 {
     _context = context;
     _mapper  = mapper;
     _logger  = logger;
 }
示例#21
0
 public PeopleController(AdventureWorks2017Context context)
 {
     _context = context;
 }
 public PersonRepository(AdventureWorks2017Context dbContext) : base(dbContext)
 {
 }
示例#23
0
        public static void Execute()
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            using var context = new AdventureWorks2017Context();

            var addresses = context.Address;
            var businessEntityAddresses = context.BusinessEntityAddress;
            var stateProvinces          = context.StateProvince;
            var countryRegions          = context.CountryRegion;
            var salesTerritories        = context.SalesTerritory;

            var query = businessEntityAddresses
                        .Join(addresses,
                              businessEntity => businessEntity.AddressId,
                              address => address.AddressId,
                              (businessEntity, address) => new
            {
                businessEntity,
                address
            })
                        .Join(stateProvinces,
                              businessEntity => businessEntity.address.StateProvinceId,
                              stateProvince => stateProvince.StateProvinceId,
                              (businessEntity, stateProvince) => new
            {
                businessEntity,
                stateProvince
            })
                        .Join(countryRegions,
                              businessEntity => businessEntity.stateProvince.CountryRegionCode,
                              countryRegion => countryRegion.CountryRegionCode,
                              (businessEntity, countryRegion) => new
            {
                businessEntity,
                countryRegion
            })
                        .Join(salesTerritories,
                              businessEntity => businessEntity.businessEntity.stateProvince.TerritoryId,
                              salesTerritory => salesTerritory.TerritoryId,
                              (businessEntity, salesTerritory) => new
            {
                businessEntity,
                salesTerritory
            })
                        .Where(businessEntity => businessEntity.businessEntity.countryRegion.CountryRegionCode.Equals("US"));

            foreach (var queryObject in query)
            {
                //Print first three rows from table
                //And yes I know the naming is shit, but I don't care :)
                Console.WriteLine("{0} {1} {2}", queryObject.businessEntity.businessEntity.businessEntity.businessEntity.BusinessEntityId,
                                  queryObject.businessEntity.businessEntity.businessEntity.address.AddressId,
                                  queryObject.businessEntity.businessEntity.businessEntity.businessEntity.AddressTypeId);
            }

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            var ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:00}";

            //; is for my shell script, which outputs to a csv
            Console.WriteLine("RunTime " + elapsedTime + ";");
        }
 public AddressRepository(AdventureWorks2017Context context)
 {
     _context = context;
 }