.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

DataBinding to ComboBox using WCF RIA and Entity Framework

Posted By:Manas Patnaik       Posted Date: January 06, 2011    Points: 75    Category: Silverlight    URL: http://www.dotnetspark.com  

Cascading Combo Box Data Using RIA in Silverlight 4

Having introduced to the concept of WCF RIA services with EF and Silverlight in my earlier post , now its time to take up the issues we usually face in day to day coding activity.So in this post we will replicate cascade combo box loading scenario , where the data of other combo depends on the selection of first .

Here we have 2 combo box Product and Version , Depending upon product selection the versions should get populated.


Now as usual we will follow the steps ,

  • Bind Data To Product Combo
  • On Selected Index change event of Product Combo we will bind to Version Combo
Binding Data To Product Combo Box

As in my earlier post , i have created a Domain Context called myDomainContext using Entity Framework code generation.


Using myDomainContext Entity Query  we will bind  the product  data to the combo box.

  1. myDomainContext cont = new myDomainContext();
  2. LoadOperation<PRODUCT> prd = cont.Load(cont.GetPRODUCTsQuery());
  3. cmbProducts.ItemsSource = prd.Entities;

Now on selection changed event if you will try to bind it to version Combo.

On Selection Changed

Create a custom EntityQuery based on the combobox selection load the query using LoadOperation. As all queries from a domain context are executed asynchronously. To execute the query, we are passing  the EntityQuery object as a parameter in the Load method.

  1. private void cmbProducts_SelectionChanged(object sender, SelectionChangedEventArgs e)
  2. {
  3. myDomainContext cont = new myDomainContext();
  4. ComboBox cmb = (ComboBox)sender;
  5. EntityQuery<VERSION> query = from c in cont.GetVERSIONsQuery()
  6. where c.VERSION_PRODUCTID == ((PRODUCT)cmb.SelectedItem).PRODUCTID
  7. select c;
  8. LoadOperation<VERSION> prd = cont.Load(query);
  9. cmbVersions.ItemsSource = prd.Entities;
  10. }

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend