Complex OrderBy with ContentQuery

Topics: Customizing Orchard, General, Writing modules
Jun 28, 2011 at 4:57 PM

Is there any way to do a complex OrderBy with IContentQuery?  Maybe I'm missing something, but it seems like it's severely limited in that it a) only allows property specifier linq queries (i.e. obj => obj.MyProperty) and b) doesn't allow for for chaining (i.e. orderby...thenby...etc).

Am I missing something or should I file a bug?

Coordinator
Jun 28, 2011 at 5:37 PM

Content manager queries are a small subset of what you could with Linq. Not as an oversight but because we implemented what we needed, as needed and as time permitted. Contributions are welcome ;)

Jun 28, 2011 at 5:42 PM

Cool, I'm actually digging into it now.  I'll let you know if I get anywhere.

Jun 28, 2011 at 5:55 PM

Any thoughts as to why I'm not able to suppress the DefaultContentQuery?  I'm playing around with this and have [OrchardSuppressDependency("Orchard.ContentManagement.DefaultContentQuery")] however the DefaultContentQuery is always returned from the content manager.

Coordinator
Jun 28, 2011 at 6:00 PM

I have no idea but this is a case where I would encourage you to submit a patch rather than build a module.

Jun 28, 2011 at 6:01 PM

Absolutely I will, I'm just playing around with it in my current module.

Jun 29, 2011 at 2:35 PM

Bertrand, does Andre Rodrigues post on here?  I got 90% done with implementing this, then ran into a wall with the outdated nhibernate linq provider.  Then I checked out the upgraded libs branch and it looks like Andre has already implemented this.  I can't really test it out with my current code though. Looking at his code, I think it should allow full orderby queries.  Any way to check with him on that?  Thanks.

Coordinator
Jun 29, 2011 at 6:49 PM

I'll summon him ;)

Developer
Jun 29, 2011 at 7:09 PM

... and I've been summoned :)

Hey ldhertet :)

Indeed I've been working on rolling out the new, embedded, nhibernate linq provider. There's still work to be done but if you sync to that branch you should have an working orchard installation on those new libs. At this moment there was no plan on extending the provider to allow additional orderby criterias but if this is something you need, you could investigate a contribution into this new code. Maybe if you share the contribution you had in mind I may be able to adjust it to the new libs code.

Jun 29, 2011 at 7:26 PM

Thanks andre, 

Unfortunately I can't try to integrate my work with your updated libs branch because (last time I tried) there were way too many changes and all my modules were broken.  I've uploaded the file that I was working on here, but I'm doubting it will be of much use to you.  First of all, from looking at your code, it seems like you're doing a lot more complicated stuff than I am.  Secondly, I was trying to implement it as close (structurally) as I could to the existing implementation, to make it easy to understand if I submitted it as a patch.  But that probably doesn't make sense otherwise.  Lastly, I'm not even sure if it is fully functional, as I couldn't test the parts that query joined records due to the lack of a join implementation in the old LINQ provider.

As to chaining the OrderBy's, I think it would be fairly trivial to implement, but one thing that I think should be considered is how the existing functionality works.  I found that it differs from the standard LINQ implementation in that it actually does kind of allow you to chain OrderBy's.  In standard Linq, if I did collection.OrderBy(something).OrderBy(something), the second OrderBy would be the only one that took affect.  What I would like to see is for you guys to expose ThenBy and ThenByDescending in the interface.  You could pass this through easily enough in Linq.  BUT, that would be a break from the current behavior.

Let me know if you have any questions.

Luke

Developer
Jun 29, 2011 at 7:32 PM

Oh I see. Indeed the upgraded libs is synched to dev which is future work and not 1.2 anymore... :( If you want something for 1.2, that'd have to be on the "old" / external LINQ Provider.

As time allows, I will see if i can squeeze those "thenby" criterias into the contentquery provider.