private void customerIDComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Customer selectedCustomer = this.customerIDComboBox.SelectedItem as Customer; try { // Load the first page of related orders for the selected customer. context.LoadProperty(selectedCustomer, "Orders"); // Load all remaining pages. while (selectedCustomer.Orders.Continuation != null) { selectedCustomer.Orders.Load( context.Execute <Order>(selectedCustomer.Orders.Continuation.NextLinkUri)); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Instantiate the data service context. context = new NorthwindEntities(svcUri); try { // Create a new collection for binding based on the LINQ query. trackedEmployees = new DataServiceCollection <Employees>(context.Employees); // Load all pages of the response at once. while (trackedEmployees.Continuation != null) { trackedEmployees.Load( context.Execute <Employees>(trackedEmployees.Continuation.NextLinkUri)); } // Bind the root StackPanel element to the collection; // related object binding paths are defined in the XAML. LayoutRoot.DataContext = trackedEmployees; if (trackedEmployees.Count == 0) { MessageBox.Show("Data could not be returned from the data service."); } // Select the first employee in the collection. employeesComboBox.SelectedIndex = 0; } catch (DataServiceQueryException ex) { MessageBox.Show(ex.Message); } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { // Initialize the context for the data service. context = new NorthwindEntities(new Uri(svcUri)); // Create a LINQ query that returns customers with related orders. var customerQuery = from cust in context.Customers where cust.Country == customerCountry select cust; //<snippetBindPagedDataSpecific> // Create a new collection for binding based on the LINQ query. trackedCustomers = new DataServiceCollection <Customer>(customerQuery); // Load all pages of the response at once. while (trackedCustomers.Continuation != null) { trackedCustomers.Load( context.Execute <Customer>(trackedCustomers.Continuation.NextLinkUri)); } //</snippetBindPagedDataSpecific> // Bind the root StackPanel element to the collection; // related object binding paths are defined in the XAML. LayoutRoot.DataContext = trackedCustomers; } catch (DataServiceQueryException ex) { MessageBox.Show("The query could not be completed:\n" + ex.ToString()); } catch (InvalidOperationException ex) { MessageBox.Show("The following error occurred:\n" + ex.ToString()); } }
private void ClientCredentials_Loaded(object sender, RoutedEventArgs e) { string userName = string.Empty; string domain = string.Empty; SecureString password = new SecureString(); // Get credentials for authentication. LoginWindow login = new LoginWindow(); login.ShowDialog(); if (login.DialogResult == true && login.userNameBox.Text != string.Empty && login.passwordBox.SecurePassword.Length != 0) { // Instantiate the context. context = new NorthwindEntities(serviceUri); // Get the user name and domain from the login. string[] qualifiedUserName = login.userNameBox.Text.Split(new char[] { '\\' }); if (qualifiedUserName.Length == 2) { domain = qualifiedUserName[0]; userName = qualifiedUserName[1]; } else { userName = login.userNameBox.Text; } password = login.passwordBox.SecurePassword; // Set the client authentication credentials. context.Credentials = new NetworkCredential(userName, password, domain); // Define an anonymous LINQ query that returns a collection of Customer types. var query = from c in context.Customers where c.Country == "Germany" select c; try { // Instantiate the binding collection, which executes the query. binding = new DataServiceCollection <Customer>(query); while (binding.Continuation != null) { // Continue to execute the query until all pages are loaded. binding.Load(context.Execute <Customer>(binding.Continuation.NextLinkUri)); } // Assign the binding collection to the CollectionViewSource. customerAddressViewSource = (CollectionViewSource)this.Resources["customerViewSource"]; customerAddressViewSource.Source = binding; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (login.DialogResult == false) { MessageBox.Show("Login cancelled."); } }