SIGN UP MEMBER LOGIN:    
ARTICLE

Step By Step Guide to WCF RIA enabled SL4 application with Entity Framework

Posted by Manas Patnaik Articles | Silverlight with C# January 06, 2011
Here we will create a Silverlight 4 based application with WCF RIA services and Entity Framework.
Reader Level:

In my last post we discussed the concepts of WCF Ria services; this post is a continuation of my earlier post. Here we will create a Silverlight 4 based application with WCF RIA services and Entity Framework. Before going through the article make sure you have downloaded the latest SDKs from Microsoft as mentioned in my last post.

Well we will develop a simple database centric user management system where the admistrator is going to view and edit user detail. For this app we will use remote SQL Server with the following tables.

Entity Framework, Silverlight 4.0, WCF RIA Service

Create the Project
  • Open VS 2010. Select Microsft installed Silverlight Business Template and click Ok. After the project is created compile it. You will find a structured application with pre-defined WCF RIA support. It will also have predefined user registration and login module.

Entity Framework, Silverlight 4.0, WCF RIA Service Entity Framework, Silverlight 4.0, WCF RIA Service
-
Generate Data Model through EF at Server Project
  • Add Ado.Net Entity model to server side Project.

  • Here I am using remote SQL Sserver from shared hosting, so select connection and proceed.

Entity Framework, Silverlight 4.0, WCF RIA Service

Entity Framework, Silverlight 4.0, WCF RIA Service

  • A more detailed description of adding EF can be found from this blog post.

Add Domain Service to Server Project
  • Add a new item to the server side project named "UM_Server_DomainService.cs". Before adding, make sure that you have compiled the project.

Entity Framework, Silverlight 4.0, WCF RIA ServiceEntity Framework, Silverlight 4.0, WCF RIA Service
 

  • This domain service class will expose the data entities and operations of server side project to the client side project

Entity Framework, Silverlight 4.0, WCF RIA Service

This will add up 2 classes as shown in figure besides.

Entity Framework, Silverlight 4.0, WCF RIA Service
 

  • Compile the project. Next we will move on the client side project for data binding.

Load controls, using the Data Context at Client side project (Data Binding Through Code)
  • If you check the hidden folder "Generated_Code" you will find auto generated DataContext code for the client.

Entity Framework, Silverlight 4.0, WCF RIA Service
 

  • From DomainClient we can communicate to the domain service at server. From client side we can perform 3 fundamental kinds of operations, such as Query, Invoke and Submit. (The details regarding it are out of the scope of this post; still you can Refer Here)

  • So to bind the data, go to the Home Page and Drag and Drop a combo box.

  • Next steps will be .

Creating a Query Based Operation ,

Assigning Item data source to the control

  1. private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)

  2. {

  3. UserManagementSystem.Web.UM_Server_DomainContext context =

  4. new UserManagementSystem.Web.UM_Server_DomainContext();

  5. LoadOperation<IT_USER> usersQueryOperation = context.Load(context.GetIT_USERQuery());

  6. cmbUsers.ItemsSource = usersQueryOperation.Entities;

  7. cmbUsers.DisplayMemberPath = "UserName";

  8. }


So the code as above will fetch the data and load the users.

Entity Framework, Silverlight 4.0, WCF RIA Service

Alternatively we can also use the Drag and Drop feature of VS 2010 to create binding. Simply go to Home page and open the Data Source Navigation pane.

Entity Framework, Silverlight 4.0, WCF RIA Service

Entity Framework, Silverlight 4.0, WCF RIA Service

That's it; is it not cool? For my goodness the whole lots of work suddenly looks so simple, hats off to Microsoft Smile.

Your comments are welcome and more details I will try to post in future.

Login to add your contents and source code to this article
share this article :
post comment
 

Ya sure .I have used sql database from shared hosting.I will change the datasource and add the source. Thx for suggestion.

Posted by Manas Patnaik Jan 07, 2011

It should be good for readers if you can attach your sample project too :))))

Posted by Raj Kumar Jan 07, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor