コード例 #1
0
        /// <summary>
        /// Reusable method to query data, unlike the example above changes are made in
        /// one place in code.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void IncludeStatementsUsingExtensionButton_Click(object sender, EventArgs e)
        {
            var customerIdentifier = ((CustomerLister)CustomerListBox.SelectedItem).Id;;

            using (var context = new NorthwindContext())
            {
                context.Diagnostics = LogConsoleCheckBox.Checked;
                var customer = await context.CustomerPartial(customerIdentifier);

                FirstNameTextBox.Text   = customer.Contact.FirstName;
                LastNameTextBox.Text    = customer.Contact.LastName;
                ContactTypeTextBox.Text = customer.ContactTypeIdentifierNavigation.ContactTitle;
                CountryTextBox.Text     = customer.CountryIdentifierNavigation.Name;
            }

            /*
             * Alternate to using an extension method as per above
             */
            using (var context = new NorthwindContext())
            {
                var customer = await CustomerHelpers.CustomerEntityAsync(context, customerIdentifier);
            }
        }