Autos Code Example

The sample code is based on the the Autos repository example used through this site. The repository has the fields you expect to see that describe an automobile: make, model, year, city, state, etc.

Add Data

The webservice was added to VS.NET 2005 as a service reference. The strongly-typed objects were generated and added to the project by VS.NET. The service reference was named "DataService". The following code will create a data item and add it to the automobile repository. Notice that the object actually has fields like make, model, city, etc. These fields are defined in the repository editor by its author.

C#
DataService.DataServiceClient service = new Autos.DataService.DataServiceClient();
Autos.DataService.AutoItem listing = new Autos.DataService.AutoItem();
listing.City = "Atlanta";
listing.Condition = "New";
listing.Description = "My Description";
listing.Invoice = "ABC-123";
listing.Make = "Toyota";
listing.Model = "Corolla";
...other fields....
service.AddData(listing);

Query Data

You can query data just as easily. You must create a query object and set its parameters. In this example, there are no properties set on the query object. In this case, all records will be included in the set, paginated 10 records at a time. The results object has a RecordList object that contains all returned records. The default is 10 records, but you can set this to any value you wish.

C#
DataService.DataServiceClient service = new DataService.DataServiceClient();
DataService.AutoUrlQuery query = new DataService.AutoUrlQuery();
DataService.AutoItemResults results = service.Query(query);
foreach (DataService.AutoItem item in results.RecordList)
{
System.Diagnostics.Debug.WriteLine(item.Make);
System.Diagnostics.Debug.WriteLine(item.Model);
System.Diagnostics.Debug.WriteLine(item.State);
System.Diagnostics.Debug.WriteLine(item.Price);
}

Using Dimension Data

The above code is no different that adding and querying data from a standard database. The real power of the CeleriQ engine comes in the dimension groupings. The following code builds links for states. Each link has a state name as well as how many items match that criteria for the State field. When the user clicks the link the MyPage.aspx will pick up on the url query and retrieve the matching items. The links will look like this:

C#
foreach (DataService.RefinementItem refinement in results.CompleteStateDimension.RefinementList)
{
HyperLink link = new HyperLink();
link.Text = refinement.FieldFilter + " (" + refinement.ItemCount + ")";
link.NavigateUrl = "MyPage.aspx?d=" + refinement.DVIdx;
}