public List <Customer> CompleteCustomersTest() { using (var context = new NorthWindAzureContext()) { return(context.PartialCompleteCustomers().ToList()); } }
/// <summary> /// Get all customers without children /// </summary> /// <returns></returns> public async Task <List <Customer> > GetAllCustomers() { using (var context = new NorthWindAzureContext()) { return(await Task.Run(() => context.Customers.Select(customer => customer).ToList())); } }
/// <summary> /// Example for projection of a specific model /// </summary> /// <returns></returns> public List <CustomerCountryListItem> ProjectionTest() { using (var context = new NorthWindAzureContext()) { List <CustomerCountryListItem> results = context.Customers.Select(Customer.Projection).ToList(); return(results); } }
/// <summary> /// Dynamic sort by property name and order ascending or descending /// </summary> public void SortTest() { using (var context = new NorthWindAzureContext()) { var results = context.Customers.ToList().Sort1("CompanyName DESC"); Console.WriteLine(); } }
/// <summary> /// Next attempt, pass in a Nullable Int array of country identifiers /// </summary> /// <param name="countryIdentifiers"></param> private void ArticleSample2(int?[] countryIdentifiers) { using (var context = new NorthWindAzureContext()) { var results = context.Customers .Where(customer => countryIdentifiers.Contains(customer.CountryIdentifier)) .ToList(); } }
/// <summary> /// How a developer might try to perform a IN condition yet this /// is hard coded, not suited to work with dynamic values. /// </summary> private void ArticleSample1() { using (var context = new NorthWindAzureContext()) { var results = context.Customers. Where(customer => customer.CountryIdentifier == 8 || customer.CountryIdentifier == 7) .ToList(); } }
public async Task <List <CategoryCheckedListBox> > GetAllCategories() { using (var context = new NorthWindAzureContext()) { return(await Task.Run(() => context.Categories.Select(category => new CategoryCheckedListBox() { CategoryID = category.CategoryID, CategoryName = category.CategoryName }).ToList())); } }
/// <summary> /// Example for building a where predicate with an expression /// </summary> public void BuilderTest() { var test = Builder.Build <Customer, string>( customer => customer.ContactType.ContactTitle, Operator.EQUAL, "Owner"); using (var context = new NorthWindAzureContext()) { var results = context.Customers.Where(test).ToList(); Console.WriteLine(); } }
/// <summary> /// Get customers by dynamic property and value /// </summary> /// <param name="propertyName"></param> /// <param name="value"></param> /// <returns></returns> public async Task <List <Customer> > GetCustomersList(string propertyName, string value) { Func <Customer, bool> query = DynamicQueryWithExpressionTrees(propertyName, value); using (var context = new NorthWindAzureContext()) { return(await Task.Run(() => context.Customers .Include(customer => customer.Country) .Where(query).Select(customer => customer) .ToList())); } }
public async Task <List <CountryItem> > GetAllCountries() { using (var context = new NorthWindAzureContext()) { return(await Task.Run(() => context.Countries.Select(country => new CountryItem() { CountryIdentifier = country.CountryIdentifier, Name = country.Name }).ToList())); } }
/// <summary> /// Using expressions to build a predicate for obtaining data /// by multiple key values /// </summary> /// <returns></returns> public List <Customer> ExtensionCustomersContainsIdentifiersTest() { var ids = new List <int> { 1, 2, 3 }; using (var context = new NorthWindAzureContext()) { return(context.Customers .Include(customer => customer.Contact) .WithIdendifier(cust => cust.CustomerIdentifier, ids) .ToList()); } }
/// <summary> /// Get subset of customers focusing on primary keys /// </summary> /// <returns></returns> public async Task <List <CustomerNameIdentifier> > CustomerNameWithIdentifiers() { using (var context = new NorthWindAzureContext()) { return(await Task.Run(() => context.Customers .Include(customer => customer.Country) .Select(customer => new CustomerNameIdentifier() { CustomerIdentifier = customer.CustomerIdentifier, CompanyName = customer.CompanyName, CountryIdentifier = customer.CountryIdentifier.Value }).ToList())); } }
/// <summary> /// Using expressions to build a predicate for obtaining data /// by multiple key values /// </summary> /// <returns></returns> public void CustomerContactsTypes() { var ids = new List <int?> { 1, 2, 3 }; using (var context = new NorthWindAzureContext()) { var results = context.Customers .Include(c => c.ContactType) .WithContactTypes(item => item.ContactTypeIdentifier, ids) .ToList(); Console.WriteLine(); } }