Thursday, March 6, 2014

ASP.Net Web API + OData + $inlinecount

So, I had a nice single page application querying data from a Web API backend. As I wanted to allow searching and paging, I used the OData extensions and all was well. Until I needed to know the total number of items in the dataset after having it filtered using $filter, $top and $skip. At the time, I didn't find any easy way to do it, so I implemented a second query to the API to return the total number of items. Problem is, this second query returned the total number of items and didn't take into account any filtering I had applied in the OData query (using $filter). I let that dormant for a while...

Then came the need to have a nice navigation footer, and I used this component: http://botmonster.com/jquery-bootpag/

This component just needs to know the number of pages and at which page it currently is. But then again, we need to know the number of items to know the number of pages to display. Back at square one ;-)

I looked for ways to implement this once again and found more info this time (technology matured or better search query in Google?). Some articles suggested to force the verbose mode of OData (by using "&$format=verbosejson" or adding an accept header with a value of "application/json;odata=verbose"), to no avail. I would always receive an array with the X items I requested using the $top parameter and nothing else.

Until I came across these 2 posts on SO:
http://stackoverflow.com/questions/18428763/web-api-odata-inlinecount-not-mapped
and http://stackoverflow.com/questions/18197041/reconstructing-an-odataqueryoptions-object-and-getinlinecount-returning-null

In short, here is what I had to change:

[Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable Get()
{
return m_oItems.AsQueryable();
}

changed to:

public PageResult Get(ODataQueryOptions options)
{
IQueryable results = options.ApplyTo(m_oItems.AsQueryable());
return new PageResult(results as IEnumerable, Request.GetNextPageLink(), Request.GetInlineCount());
}

Then in my JS file, I added "&$inlinecount=allpages" to my query and where I would treat the data blob returned by $.getJSON as an array, I simply use data.Count to have the number of items that match my query, and data.Items as my array of items.

The solution looks so simple now, but took me some time to figure out. Hope this helps...

Friday, February 22, 2013

viashopia Android app

My first mobile application, made using PhoneGap 2.3.0, is available on the Google Play Store:



Also visit the brand new web site of viashopia here: http://www.viashopia.com

Tuesday, September 11, 2012

You play, we play

If you want to play Euromillions and increase your odds, a lottery syndicate is the best way to do just that. By pooling your ticket with 49 other players, your odds of winning something is multiplied by 50, for a price a tad higher than buying your own ticket in the shop.

I've played with the below syndicate and have won something on every single draw, albeit small prizes so far.

You also have the benefit of the British Euromillion draw that gives away 1 million pounds during each draw to a ticket sold in the UK. In fact, each draw gives you 50 changes to get that lucky ticket and share it between 50, which gives you 20.000£ in such a case. Gladly welcome.

Enjoy!

Thursday, August 16, 2012

Monday, May 7, 2012

Wednesday, June 29, 2011

Journée en Famille 2011

Ce 26 juin 2011, Céline Asselborn animait l'atelier sur le portage respectueux à Volaiville. Buffets, stands d'information, activités diverses, et bien sûr, la 2ème édition de la Balade des enfants portés complétaient cette journée très ensoleillée !

Photos ici:


Tuesday, April 5, 2011

Anne-Lise & Fabien

Petite vidéo prise lors de la séance photos précédent la cérémonie de mariage d'Anne-Lise et Fabien, le samedi 2 avril 2011...



Anne-Lise & Fabien from Frédéric Mauroy on Vimeo.

Canon 5D MkII + Canon EF 200 1.8L

Les photos sont ici:



Wednesday, December 22, 2010