This article demonstrates how to use RIA services with ADO.NET Entity Data Model
and how to use page navigation in Silverlight.
First of all as usual make a new Silverlight project and put name of project and
location. By default is creates 2 project like this.

Image1.
There are two projects created there one is works as client and another one web
project works as server.
Now add data model in web project and configure it to database.

Image2.

Image3
Click Next.

Image4.
Click Next. And choose database objects and click finish.

Image5
Now let's start working on client project.
First of all we have to fetch data on a grid. So declare some namespace on page.
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:my1="clr-namespace:RIAExample.Web.Services"
xmlns:my2="clr-namespace:RIAExample.Controls"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
here is DomainDataSurce
<riaControls:DomainDataSourceAutoLoad="True"
d:DesignData="{d:DesignInstancemy:Customer,CreateList=true}"Height="0"LoadedData="customerDomainDataSource_LoadedData"
Name="customerDomainDataSource"LoadSize="10"QueryName="GetCustomersQuery"
Width="0">
<riaControls:DomainDataSource.DomainContext>
<my1:CustomerDomainContext
/>
</riaControls:DomainDataSource.DomainContext>
Filtering based on customer id with text box value
<riaControls:DomainDataSource.FilterDescriptors>
<riaControls:FilterDescriptor
PropertyPath="CustomerID"
Operator="StartsWith"
Value="{BindingElementName=customerIDText,
Path=Text}">
</riaControls:FilterDescriptor>
</riaControls:DomainDataSource.FilterDescriptors>
<riaControls:DomainDataSource.GroupDescriptors>
<riaControls:GroupDescriptorPropertyPath="CustomerID"
/>
</riaControls:DomainDataSource.GroupDescriptors>--></riaControls:DomainDataSource>
DataGrid part
<my2:BusyIndicator
x:Name="busyIndicator1"
Width="400"IsBusy="{BindingElementName=customerDomainDataSource,
Path=DomainContext.IsLoading}" />
<sdk:DataGridAutoGenerateColumns="False"ItemsSource="{BindingElementName=customerDomainDataSource,
Path=Data}"
Name="customerDataGrid"RowDetailsVisibilityMode="VisibleWhenSelected"MinHeight="250"
Height="Auto">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn
Header="Customer
ID">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton
x:Name="CustomerIDHyperlink"
Content="{Binding
Path=CustomerID, Mode=OneWay}"
Click="EditHyperlink_Click"></HyperlinkButton>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn
x:Name="companyNameColumn"
Binding="{Binding
Path=CompanyName}"
Header="Company
Name" Width="SizeToHeader"
/>
<sdk:DataGridTextColumn
x:Name="contactNameColumn"
Binding="{Binding
Path=ContactName}"
Header="Contact
Name" Width="SizeToHeader"
/>
<sdk:DataGridTextColumn
x:Name="contactTitleColumn"
Binding="{Binding
Path=ContactTitle}"
Header="Contact
Title" Width="SizeToHeader"
/>
<sdk:DataGridTextColumn
x:Name="countryColumn"
Binding="{Binding
Path=Country}"
Header="Country"
Width="SizeToHeader"
/>
<sdk:DataGridTextColumn
x:Name="postalCodeColumn"
Binding="{Binding
Path=PostalCode}"
Header="Postal
Code" Width="SizeToHeader"
/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<sdk:DataPager
Height="26"HorizontalAlignment="right"
Name="dataPager1"PageSize="10"VerticalAlignment="Top"
Width="Auto"
Source="{BindingElementName=customerDomainDataSource,
Path=Data}" />
DataForm
<dataform:DataForm
x:Name="dataForm1"
Header="Customer
Information"AutoGenerateFields="False"AutoEdit="False"AutoCommit="False"CurrentItem="{BindingSelectedItem,ElementName=customerDataGrid}"
Margin="0,12,0,0"DeletingItem="dataForm1_DeletingItem">
<dataform:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataform:DataField
Label="Customer
ID">
<TextBoxIsReadOnly
Text="{BindingCustomerID,
Mode=OneWay}" />
</dataform:DataField>
<dataform:DataField
Label="Company
Name">
<TextBox
Text="{BindingCompanyName,
Mode=TwoWay}" />
</dataform:DataField>
<dataform:DataField
Label="Contact
Name">
<TextBox
Text="{BindingContactName,
Mode=TwoWay}" />
</dataform:DataField>
<dataform:DataField
Label="Contact
Title">
<TextBox
Text="{BindingContactTitle,
Mode=TwoWay}" />
</dataform:DataField>
<dataform:DataField
Label="Country">
<TextBox
Text="{Binding
Country, Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnExceptions=True }"
/>
</dataform:DataField>
<dataform:DataField
Label="PostalCode">
<TextBox
Text="{BindingPostalCode,
Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnExceptions=True }"
/>
</dataform:DataField>
</StackPanel>
</DataTemplate>
</dataform:DataForm.EditTemplate>
</dataform:DataForm>
<StackPanel
Orientation="Horizontal"HorizontalAlignment="Right"
Margin="0,12,0,0">
<Button
x:Name="submitButton"
Width="75"
Height="23"
Content="Submit"
Margin="4,0,0,0"
Click="submitButton_Click"/>
</StackPanel>
Now run the application, result should be like this.

Image6.
Now if you enter some text in text box then result should be filter
automatically.

Image7.
Now if you click on customer id and you want sent that id t another page then u
have to write code like this.
<sdk:DataGridTemplateColumn
Header="Customer
ID">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton
x:Name="CustomerIDHyperlink"
Content="{Binding
Path=CustomerID, Mode=OneWay}"
Click="EditHyperlink_Click"></HyperlinkButton>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
private void EditHyperlink_Click(object sender,
System.Windows.RoutedEventArgs e)
{
Customer currentEvent = customerDataGrid.SelectedItemasCustomer;
if
(currentEvent != null)
{
NavigateToEditEvent(currentEvent.CustomerID);
}
}
private void NavigateToEditEvent(stringeventId)
{
NavigationService.Navigate(newUri("/Detail?CustomerID="
+
eventId, UriKind.Relative));
}
Detail page should be like this.

Image8.
Hope this will help. If you have any questions then download attached project or
drop me a comment in www.c-sharcorner.com
comment section.


Almond MonteagudoPosted Jun 6, 2012, 9:45 PM EDT
Hello, I am new with silverlight. Would like to ask if you have implemented a text box search where in the field type is of date. Also, can it be done using related field such a customer table where there is a fields name cust_supplier_idno which is related to the supplier table's supplier_idno. I have been looking for such a solution and having a hard time looking for one. Most of the solutions are in MVVM and i wondering if it could be implemented using EF an RIA Services. Thanks in advance guys. almond
habPosted Jun 15, 2010, 6:39 AM EDT
I have an iissue that is caused after update a model from the database. Here are the sequence of events. 1) Open the *.edmx file (e.g. Model1.edmx) from the Web project 2) Right-Click and slect “Update Model from the Database” 3) Follow the wizard and updated the changes I’ve made to the database (for example , adding a new column) 4)At this point I see the tables my Model1.edmx are successfully updated (I could see the extra column I’ve added) Also, I can retrieve (read) data and display it on my DataGrid 5) BUT, could not update, delete or add records back to the database. Please note that before I have execute the “Update Model from the Database” (#2), I was able to do update , delete and remove.
m lPosted Jun 3, 2010, 3:20 AM EDT
Thanks Raj, I cannot find the attached project mate. Has it been uploaded? Thanks Mick