ordering

NHibernate + ASP.Net MVC - how to order data in strongly typed manned according to user selected field

I'm presenting data for users in a grid (ExtJS) with remote sorting and paging. Let's say I have a grid with some Orders. Order entity looks like Order{OrderNumber, Customer, Date, Address{Street, City, PostCode}}. Customer is mapped by NH as relation, Address is mapped as component. Data presented in the grid are flattened to columns na...

PHP's USORT Callback Function Parameters

This is a really esoteric question, but I'm genuinely curious. I'm using usort for the first time today in years, and I'm particularly interested in what exactly is going on. Suppose I've got the following array: $myArray = array(1, 9, 18, 12, 56); I could sort this with usort: usort($myArray, function($a, $b){ if ($a == $b) return...

How to use two ordering criteria in C#?

I have a set of strings. I want to select all strings that contains another string. But I want to have as the first items, the items that start with the search, and then, alphabetically the other items. But the following code doesn't work: items = items .Where(a => a.Contains(contained)) .OrderBy(a => a) ; var startsWith = item...

How Can I Write a SQL Query That Will Sort the Results Based on a Condition?

This question is based on this other question of mine, and uses all of the same basic info. That link shows my table layouts and the basic gist of the simple join. I would like to write another query that would select EVERY record from Table1, and simply sort them by whether or not Value is less than the linked Threshold. Again, I ...

What is the best way to store the order between rows in the database?

I am cloning and extending the Google Tasks application. I want to be able to store the rows order. I have created a field in the database, named rowNumber. When the user inserts a row in the middle of others, I have to update this field in many other rows to achieve the desired output. There is a better way to do it? BTW the applicatio...

django - QuerySet recursive order by method

I may have a classic problem, but I didn't find any snippet allowing me to do it. I want to sort this model by its fullname. class ProductType(models.Model): parent = models.ForeignKey('self', related_name='child_set') name = models.CharField(max_length=128) def get_fullname(self): if self.parent is None: ...

LINQ Orderby clause is causing weird results

I have created the following LINQ query to demonstrate the problem: string[] dateStrings = new string[] { "2009-07-20 13:00:00", "2009-07-20 16:00:00", "2009-07-20 09:00:00" }; DateTime dateValue = DateTime.MinValue; var results = from dateString in dateStrings where DateTime.TryParse(dateString, out dateValue) orderby...

Datagridview on RowLeave not assigning proper values to booleans

I have a DataViewGrid I populated from a DataTable in a query to a DB. While trying to capture the Row_Leave event, so I could properly update it, I can't seem to capture the latest value in boolean columns. If I update just a text field, when I access the underlying DataSource I get the latest value I entered, buy if I access the boole...

C++ templated container class: How to best support both ordered and un-ordered item types?

Hi all, I'm writing a templated C++ generic container class that can optionally maintain its contents in a well-defined order. Previously it used function pointers to order its contents in a sensible type-specific way, but I am attempting to change it to use templated functor arguments instead. Since it's often the case that the clas...

Trying to find the top 3 properties of a POCO instance.

Hi folks, I have a simple POCO class that contains the student's scores. eg. Math - 83% Engrish - 82% Chemistry - 81% Drama - 100% etc.. Is there a way (using linq?) that i could figure out the top 3 properties ordered by score? I'm assuming the final object will be an IList of an anonymous type, which will have two fields. Name (t...

C#: How to implement IOrderedEnumerable<T>

I want to implement some various algorithms for practice, just to see how bad I really am and to get better :p Anyways, I thought I would try to use IEnumerable<T> and IOrderedEnumerable<T> and other .Net collection types just to be compatible (so that what I write can be used more easily later). But I can't find a way to return an ins...

stl ordering - strict weak ordering

Why does STL work with a comparison function that is strict weak ordering? Why can't it be partial ordering? ...

How to reorder a 60mb CSV file

I have a .csv file that is ordered in a certain way. I want to reorder it by another field. Your ideas would be much appreciated. I only have to do this once, not multiple times, so performance is not too much of an issue. What I am thinking. If I just create an object (java) to hold each of the fields and then create an ArrayList of ...

Trying to find the top 3 properties of a POCO instance, Part 2

Hi folks, a month ago I asked this question: Trying to find the top 3 properties of a POCO instance. Got an answer, worked well. Now, I'm trying to find the top 3 properties of a POCO object (like my previous question) but where each property has a WEIGHT. The value of the property comes first. The weight then comes in second ... if tw...

LINQ Keyword search with orderby relevance based on count (LINQ to SQL)

This is what i have now as a very basic search: var Results = from p in dx.Listings select p; if (CategoryId > 0) Results = Results.Where(p => p.CategoryId == CategoryId); if (SuburbId > 0) Results = Results.Where(p => p.SuburbId == SuburbId); var OrderedResults = Results.OrderByDescending(p => p.ListingType); OrderedResults = OrderedRe...

c# string sorting VS Oracle string sorting

Hi! I have to sort a list of strings in exactly the same way as they are returned to me from an oracle database. Unfortunately Oracle returns them in such a way, that numeric characters are sorted after alphabetic. For example: Alabama x-men 100 new ideas 9 months ... How could I sort a list of strings in C# in such a way? ...

How does this "Lexographic order generation algorithm" work?

from Wikipedia: Lexicographical order generation For every number k, with 0 ≤ k < n!, the following algorithm generates the corresponding lexicographical permutation of the initial sequence sj, j = 1, ..., n: function permutation(k, s) { var int n:= length(s); factorial:= 1; for j= 2 to n- 1 { // compu...

How do I order an array of floating point numbers using a criteria other than size, using LINQ?

For example, I have an array of floating point numbers: float[] numbers = new float[] { 1, 34, 65, 23, 56, 8, 5, 3, 234 }; If I use: Array.Sort(numbers); Then the array is sorted by the size of the number. I want to sort the numbers by another criteria, so element A should go before element B if f(A) < f(B), rather than the usual ...

Mysql Ordering Query

Hello I want to run a query to get the last five records from a table, but in reverse order. Currently I have: $query = "SELECT * FROM Table ORDER BY id DESC LIMIT 5"; which isn't quite what I want. For example if the last five records are 15 16 17 18 19 I want them returned as 15 16 17 18 19 Not 19 18 17 16 15 which is what the ...

Return random rows from the best ones (i.e: 100 rows -> best 10 -> get 5 random)

Hello all again! Situation: A table with lots of photos, classified and with votes. I'm currently doing this: SELECT n.nid, n.title, ....... order by v.value desc limit 0,5 What I want is to get a random resultset after sorting my rows by its votes. Now, a table with hundreds of records is giving me the best 5 rows. Always the same 5...