Learn WCF RIA Service Part #1
It may be
bit late but let us learn WCF RIA together. I will be writing many parts on
Learning WCF RIA Services.
You can also follow my blogPart1
In this part just to get a
feeling of WCF RIA and see our one application is running on WCF RIA, I am going
to walkthrough creating first application through WCF RIA Services.
Silverlight Data Grid we will fetch and display all the records from Person
table of School database using WCF RIA Service.
Open Visual studio and create a new a new Silverlight Application.
sure you have checked the Enable WCF RIA Service checkbox.
will have two projects in the solutionCreating DataModel
us create a DataModel. I am going to use School database here.
step is to create database. We are going to use School database. Script of sample School Database copy from here
click on Server Project [web project
] and add a new item
ADO.Net Entity model from Data tab.
the option generate from Database. If Database you want to use is listed in
drop down the choose that else create a New Connection.
server name and authentication and choose the database.
leave default name for connection string in config file or give a unique name.
and after selecting table click finish. Note:
Make sure after creating Data Model you have built the project. This is a
important step Creating Domain Service
Right click on Server
Project [web project
] and add a new item. From web tab select Domain
available Data context class from drop down. And select Person class from list
this step you will get DomainService1.cs
class created in the web
are two things to notice about the class.
1. Class is inherited from
2. Attributed with
. Fetching Data from at Silverlight client
Build the project and add the namespace
a Data Grid on design
adding Data Grid xaml will look like below
At the code behind now we need to fetch
the data from Domain service. For that
1. Create an instance of Domain
Load the entity set to be bind as item source of data grid. MainPage.xaml.cs
public partial class MainPage : UserControl
DomainService1 context = new DomainService1();
LoadOperation loapPerson = context.Load(context.GetPeopleQuery());
myGrid.ItemsSource = loapPerson.Entities;
F5 to run the application,