本文整理汇总了C#中System.Data.Services.Client.DataServiceCollection<T>类的典型用法代码示例。如果您正苦于以下问题:C# DataServiceCollection<T>类的具体用法?C# DataServiceCollection<T>怎么用?C# DataServiceCollection<T>使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataServiceCollection<T>类属于System.Data.Services.Client命名空间,在下文中一共展示了DataServiceCollection<T>类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomerOrdersWpf
//引入命名空间
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using NorthwindClient.Northwind;
namespace NorthwindClient
{
public partial class CustomerOrdersWpf : Window
{
private NorthwindEntities context;
private DataServiceCollection<Customer> trackedCustomers;
private const string customerCountry = "Germany";
private const string svcUri = "http://localhost:12345/Northwind.svc/";
public CustomerOrdersWpf()
{
InitializeComponent();
}
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.Expand("Orders")
where cust.Country == customerCountry
select cust;
// Create a new collection for binding based on the LINQ query.
trackedCustomers = new DataServiceCollection<Customer>(customerQuery);
// 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 saveChangesButton_Click(object sender, RoutedEventArgs e)
{
// Save changes to the data service.
context.SaveChanges();
}
}
}