Below example shows how we can create a Data Service using Visual Studio 2008.Follow the same steps as in Article Silverlight 3 – Part 1. Then follow the below steps.Select Entity Data Model as below And select a database to generate a model. We will use a Northwind sample database as below. Select all the tables and create Entity Model. Now create a Data Service as below Add SampleService.svc and add the below code to code behind Now we can add the service to Silverlight project. To show data in silverlight will just add DataGrid to silverlight MainPage.xaml and code behind as below.Add data grid in XAML Add the below code in code behind. In silverlight that data retrival method should execute in Async Mode only otherwise you will get Exceptions.
ServiceReference1.NorthwindEntities myEnt = null; public MainPage() { InitializeComponent(); myEnt = new SilverlightwithService.ServiceReference1.NorthwindEntities(new Uri(HtmlPage.Document.DocumentUri,"SampleService.svc")); var dsQuery = (DataServiceQuery<Products>)(from p in myEnt.Products select p); dsQuery.BeginExecute(result => test.DataContext = dsQuery.EndExecute(result).ToList(), null); }
And if you execute the page will look like below. You see all the products in the Grid using Data Service.
Latest Articles
Latest Articles from Sudhakarj21
Comments or Responses
Login to post response