Creating CRUD application with RadDomainDataSource for Silverlight

by XAML Team | Comments 6

I will extend my colleague’s blog post series regarding RadDomainDataSource control with an example how to create simple CRUD (Create, Read, Update and Delete) application. For more information how to load data initially you can take a look at this blog post. Along with RadDomainDataSource control Telerik provides codeless solution for CRUD operations powered by WCF RIA Services. The solution is a combination between RadGridView and RadDomainDataSource.

 

First let’s create a default Silverlight project as following:

 

crudapplication_creation

 

Next step is to create ADO.NET Entity data model called Northwind.edmx. For the sake of the example I’ll create this entity model with a Northwnd.mdf file which is located in WEB.project App_Data directory. You will need working (started) SQL Server EXPRESS service on your machine (or you have to change connection string accordingly).

 

entitymodel_creation2

 

Hint: Do not forget to rebuild web project on this stage.

Next step is to create DomainService class with enabled editing.

 

DomainService_creation

 

Then on a client application place RadGridView control with some buttons nearby.

I’m pasting xaml code for a reference how to create binding to SubmitChanges and RejectChanges commands.

 

<Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <telerik:RadDomainDataSource x:Name="radDomainDataSource" AutoLoad="True" QueryName="GetOrder_Details"> <telerik:RadDomainDataSource.DomainContext> <web:NorthwindContext /> </telerik:RadDomainDataSource.DomainContext> </telerik:RadDomainDataSource> <StackPanel Grid.Row="0"> <telerik:RadButton x:Name="submitChangesButton" Content="Submit Changes" Command="{Binding SubmitChangesCommand, ElementName=radDomainDataSource}" CommandTarget="{Binding ElementName=radDomainDataSource}"/> <telerik:RadButton x:Name="rejectChangesButton" Content="Reject Changes" Command="{Binding RejectChangesCommand, ElementName=radDomainDataSource}" CommandTarget="{Binding ElementName=radDomainDataSource}"/> </StackPanel> <telerik:RadGridView x:Name="radGridView" Grid.Row="1" ItemsSource="{Binding DataView, ElementName=radDomainDataSource}" IsBusy="{Binding IsBusy, ElementName=radDomainDataSource}" ShowInsertRow="True"> </telerik:RadGridView> </Grid>

 

And generally that’s it – simple and codeless.

How to use the example:

  1. Create - You could add new item via Insert key or with RadGridView’s add new item UI (“Click here to add new item”).
  2. Update - Put any cell into edit mode change its value and commit row edit via Enter or click on another row. (note that ProductID field is read-only).
  3. Delete - Just select an item and press Delete key.

 

As you will notice both buttons “Submit Changes” and “Reject Changes” will be enabled when any of these operations is finished (after Row edit is finished).



Note: Changes will be populated on a server when Submit Changes button is clicked.

 

 

Download the source code

 

 

Update:

 

Enjoy!


Senior Software Developer,
Telerik XAML Team

6 Comments

Ben
It would be nice if this sample came with a solution that two separate projects. VS complains about RIA not having connection for the generated code.
Could you offer a "working" sample please?
Rossen Hristov
Hello Ben,

There are two projects in the zip file -- the client one and the server one. Can you try adding them both to a VS Solution and see how it goes?
Ben
I created an Empty solution and brought both projects in. But when I tried to build, I got an error that RIA could not generate the code. I guess the solution didn't have the proper link between the two projects, like when you start a new RIA project using templates. So, I created a brand new RIA app using template and then basically created the sample rather using he two projects.
My comment was basically, when a sample is given, it should be given as a solution (like in other blogs) than broken projects.
Nedyalko Nikolov
Hello Ben,

I've just  uploaded a solution for the example project. Thank you for your feedback.
Alexander

You have binding RadButton to concrete RadDomainDataSource.

If there is a chid table or RadGridView.RowDetailsTemplate change which be brought
in the child table cannot these commands are saved by executing not.

Need example usage RadDomainDataSource child table CRUD operation, especially if in the table there are columns GridViewComboBoxColumn

Thanks

 

Dempsey
Why in the world can't you include line-formatted code that can be easily read? There is no reason to include a code sample as a single line of text that is 1.5 miles long!
I like to PDF many of the blogs on this site, and any text longer than 0.78432 miles long causes the PDF distiller to print tiny, tiny PDF pages!
Please consider this request.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by XAML Team - or - read latest articles in Developer Tools