Creating Multiple Queries for Running Objects

Running Objects combines the power of LINQ with Metadata definition to let you leverage multiples perspectives of your queries of objects. By default, RO brings all the objects in natural order of insertion and including all the visible properties of your class. In this post, we will understand how the QueryAttribute class is structured and how to make use of it.

The QueryAttribute class

This class is the responsible to specify all the possible perspectives of a list of objects. In other words, is using this attribute that you will be able to create different lists of the same class.

Property Description
Id A unique identifier associated to each Query, it is automatically generated in case of not being supplied.
Name The label to be used in the UI and that will be used to describe the query in the class metadata model. If not specified, its value will be “All Items”.
Select The list of properties being selected. The query will display properties in order of selection. Each property must be separated by a comma and with no spaces in between.
Where Use common LINQ expressions to specify the criteria for your query. Running Objects makes use of Dynamic LINQ API, so you can use keywords such as it and also make use of regular parameters using the regular notation (@0, @1, @n).
OrderBy The purpose of OrderBy is quite simple and straight forward, the only difference is that it contains a special notation (quite easy as well). You can specify multiple criteria of sorting separated by comma with no spaces. The order of sorting can be specified by the keywords Asc and Desc where you should have colon separating the property and direction (e.g.: PropertyName:Asc ).
Skip The number of items to skip.
Take The number of items to take.
Includes An array with the name of properties that should being loaded.
Parameters The values of parameters specified in the Where property.
IsDefault Mark as true to define as the default query of the class. If multiple queries are marked as default, Running Objects will bring the first of them.
CacheDuration Set the number of seconds you want to have this query being cached. Once its value is specified, the cache will automatically be activated.
Paging Mark as true to enable paging for the given query.
PageSize If you want to customize the number of items to be loaded, specify the value of PageSize property.

 

Using QueryAttribute

Using the class Director from our Movie Database example (accessible here), we can see how beneficial it can be.

This will result in two different filters in UI and also to be used by the RESTful service layer (we will discuss it later). The following images show the two queries being applied and rendered to the user.

All Items

 

All With Movies

 

Conclusion

I hope now you can improve even more your Running Objects application. If you have questions and/or suggestions leave a comment.

 

Take care!

Eduardo

Published Monday, September 24, 2012 10:57 AM by edurdias

Comments

# Introducing Native Query Filters for Running Objects - Eduardo Dias

Pingback from  Introducing Native Query Filters for Running Objects - Eduardo Dias

Leave a Comment

(required) 
(required) 
(optional)
(required)