Retrieve an Entity based on a Query Filter

Retrieve an Entity based on a Query Filter C#.NET Code

Retrieve an Entity based on a Query Filter C#.NET Code
                    
using Intuit.Ipp.Core;
using Intuit.Ipp.Data;
using Intuit.Ipp.Security;
using Intuit.Ipp.QueryFilter;
using Intuit.Ipp.LinqExtender;
using System.Linq;

//a.Create the OAuthRequestValidator object:
OAuthRequestValidator oauthValidator = new OAuthRequestValidator( accessToken, accessTokenSecret, consumerKey, consumerKeySecret); 

//b.Create an instance of the ServiceContext class.
ServiceContext context = new ServiceContext(appToken, realmId, IntuitServicesType.QBD, oauthValidator); 


//Step 3: Create the Query Service

//Create an instance of QueryService for an entity by passing the ServiceContext created in Step 2 as the argument.

//The following example shows how to create QueryService for customer entity.
QueryService customerQueryService = new QueryService(context); 

//The following example shows how to create QueryService for Invoice entity.
QueryService invoiceQueryService = new QueryService(context); 



//Projection-Select Statements

//Projection enables you to choose a subset of the properties returned by the query.  For example, the following query returns only the Id and //GivenName properties of Customer entities:
var customerQuery = customerQueryService.Select(c => new { c.Id, c.GivenName }); 



//Filter-Where Statements

//The filter in the 'Where' clause determines which entities are returned by a query.  The filter criteria is based on the value of a property.  For //example, the following query returns all Invoice entities with a Balance property greater than 1000:
IEnumerable customers = invoiceQueryService.Where(c => c.Balance > 1000);


//The following statement gets header properties for the Invoice entities whose Customer ID properties match the values of the 'In' operator.
IEnumerable invoices = invoiceQueryService.Where(i => i.Id.In(new string[] { "QB:1234", "QB:5678", "QB:9012" }));