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


Top 5 Contributors of the Month
david stephan

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

 Subscribe to Articles

Learning WCF RIA Service Part 2: Adding Query Methods

Posted By:Dhananjay Kumar       Posted Date: January 26, 2011    Points: 75    Category: WCF    URL: http://www.dotnetspark.com  

Learning WCF RIA Service by Adding Query Methods. This is the second article of learning WCF RIA series. In this article we will see
 

Learning WCF RIA Service Part #2: Adding Query Methods

Learning WCF RIA Service Part#1 can be read here

This is the second article of learning WCF RIA series.  In this article we will see

1.  How to pass parameter in query

2.  How to return single object

3.  How to return multiple objects.

4.  How to call the query method with parameter.

In all we will add query methods in this article.

In our previous article, we fetched all the records;

Returning single object


Now let us make our query more particular.  If we want to fetch details of a particular Person of given PersonID then we need to modify. So to modify the query open DomainService1.cs and modify the query as below,




1.  We pass the parameter Id and returning the Person objects.

2.  If query is retuning single object then we will have to make [Query (IsComposable=false)].

Now to call this service we need to call the method as below,

MainPage.xaml.cs

using System.Windows.Controls;
using RIA1.Web;
using System.ServiceModel.DomainServices.Client; 
 
namespace RIA1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            DomainService1 context = new DomainService1();
            LoadOperation loapPerson = context.Load(context.GetPersonByIdQuery(1));
            myGrid.ItemsSource = loapPerson.Entities; 
 
        }
    }
}

In above we are passing person id as 1.
 
Retuning List of objects

Now if we want to pass a parameter and expecting list of objects to return, then we need to modify DomainService1.cs as below,



And we will call above method as below,

MainPage.xaml.cs

using System.Windows.Controls;
using RIA1.Web;
using System.ServiceModel.DomainServices.Client; 
 
namespace RIA1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            DomainService1 context = new DomainService1();
            LoadOperation loapPerson = context.Load(context.GetPersonsbyStart   NameQuery("b"));
            myGrid.ItemsSource = loapPerson.Entities; 
 
        }
    }
}
 Subscribe to Articles

     

Further Readings:

Responses

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