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);
}