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. 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. - 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. 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. This domain service class will expose the data entities and operations of server side project to the client side project This will add up 2 classes as shown in figure besides. 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. 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 private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e) { UserManagementSystem.Web.UM_Server_DomainContext context = new UserManagementSystem.Web.UM_Server_DomainContext(); LoadOperation<IT_USER> usersQueryOperation = context.Load(context.GetIT_USERQuery()); cmbUsers.ItemsSource = usersQueryOperation.Entities; cmbUsers.DisplayMemberPath = "UserName"; } So the code as above will fetch the data and load the users. 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. That's it; is it not cool? For my goodness the whole lots of work suddenly looks so simple, hats off to Microsoft . Your comments are welcome and more details I will try to post in future.
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.
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.
Add Ado.Net Entity model to server side Project.
Here I am using remote SQL Sserver from shared hosting, so select connection and proceed.
A more detailed description of adding EF can be found from this blog post.
Add a new item to the server side project named "UM_Server_DomainService.cs". Before adding, make sure that you have compiled the project.
This domain service class will expose the data entities and operations of server side project to the client side project
This will add up 2 classes as shown in figure besides.
Compile the project. Next we will move on the client side project for data binding.
If you check the hidden folder "Generated_Code" you will find auto generated DataContext code for the client.
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
private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
UserManagementSystem.Web.UM_Server_DomainContext context =
new UserManagementSystem.Web.UM_Server_DomainContext(); LoadOperation<IT_USER> usersQueryOperation = context.Load(context.GetIT_USERQuery()); cmbUsers.ItemsSource = usersQueryOperation.Entities; cmbUsers.DisplayMemberPath = "UserName"; }
LoadOperation<IT_USER> usersQueryOperation = context.Load(context.GetIT_USERQuery());
cmbUsers.ItemsSource = usersQueryOperation.Entities;
cmbUsers.DisplayMemberPath = "UserName";
}
So the code as above will fetch the data and load the users.
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.
That's it; is it not cool? For my goodness the whole lots of work suddenly looks so simple, hats off to Microsoft .
Your comments are welcome and more details I will try to post in future.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: