Esempio n. 1
0
        public void LinqTestOne()
        {
            IList<Address> addresses;

            // Regular EF call without AOP:
            using(var db = new AdventureWorksLT2008R2Entities())
            {
                db.Configuration.LazyLoadingEnabled = false;
                addresses = db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses).ToList();
            }
            Assert.AreEqual(2, addresses.Count);

            // Now same with LINQ-friendly AOP shortcuts:

            // Example 1: where AOP creates instance of AdventureWorksLT2008R2Entities, runs the DAL method,
            // and disposes AdventureWorksLT2008R2Entities instance - all in one shot.
            addresses = AwDal.List(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            Assert.AreEqual(2, addresses.Count);

            // Example 2: with simple AOP proxied call for existing instance of DbContext.
            using(var db = new AdventureWorksLT2008R2Entities())
            {
                db.Configuration.LazyLoadingEnabled = false;
                addresses = db.GetDbProxy(TestAspects).List(dbx => dbx.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            }
            Assert.AreEqual(2, addresses.Count);

            var address = AwDal.Single(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            Assert.IsNotNull(address);

            long adrressCount = AwDal.Count(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            Assert.AreEqual(2, adrressCount);

            adrressCount = AwDal.Count(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses), new QueryModifiers().AddSortCriteria("AddressID").AddPaging(0, 1));
            Assert.AreEqual(1, adrressCount);
        }
Esempio n. 2
0
        public void CallPerfDbContextDirectParallel()
        {
            long runsPerSec;

            runsPerSec = RunCounter.SpinPerSec(MillisecToRun, () =>
            {
                using(var db = new AdventureWorksLT2008R2Entities())
                {
                    db.Configuration.LazyLoadingEnabled = false;

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    db.QueryCustomerAddressesByCustomerID(customerIdWithManyAddresses).ToList();
                }
            });

            this.TestContext.WriteLine("db.QueryCustomerAddressesByCustomerID(customerIdWithManyAddresses) direct parallel alloc/call/disp base line test result: {0} calls/second.", runsPerSec);
        }