So, the MSDN says that "The result sequence [of Distinct] is unordered."
So here is my issue. I have a table in SQL Server that at one point had this design of fields:
id, find, replace
My idea is to take the top 10 distinct values (being that the find search term and the replace search term together are considered unique).
When you have an Identity field, regardless of the duplicates in find/replace, because the id is different, the duplicates will both get returned because the ID is technically making each entry unique.
When I remove the ID field, the result set will come back unique (in the sense of find/replace), but not ordered in the same order as the original data, but sorted starting with the "field" column and then the "replace" column.
While the Distinct, itself, does not do any sorting, from what I read, someone stated that "If you use LINQ to SQL for example then it is up to the database to decide what order it wishes to return the results..."
My current testing LINQ looks like this:
But, the weird thing is, if I don't use Distinct, they are in the original order as they appear in the table. Only when I use Distinct does the data come out sorted; which flies in the face of "Distinct is unordered".
Unless SQL is sorting them, but you would think it would sort the data the same way even when Distinct is not being used.
If this was all being left up to SQL, DISTINCT in SQL doesn't auto order fields, so why would it get the request from LINQ and think it needs to sort the result set?
Wouldn't it treat the command to get distinct values as something it needs to translate into a SQL DISTINCT, which would mean no sorting?
(The table is currently filled with numeric values, so when I have values like 1-20, it will sort 1, 10, 11...2, 20, 21, etc.)
So here is my issue. I have a table in SQL Server that at one point had this design of fields:
id, find, replace
My idea is to take the top 10 distinct values (being that the find search term and the replace search term together are considered unique).
When you have an Identity field, regardless of the duplicates in find/replace, because the id is different, the duplicates will both get returned because the ID is technically making each entry unique.
When I remove the ID field, the result set will come back unique (in the sense of find/replace), but not ordered in the same order as the original data, but sorted starting with the "field" column and then the "replace" column.
While the Distinct, itself, does not do any sorting, from what I read, someone stated that "If you use LINQ to SQL for example then it is up to the database to decide what order it wishes to return the results..."
My current testing LINQ looks like this:
VB Code:
Dim searches2 = (From x In db.tblReplaceHistories Select New With { .Display = String.Format("{0}:{1}", x.find, x.replace), .Find = x.find, .Replace = x.replace }).Distinct.Take(10)
But, the weird thing is, if I don't use Distinct, they are in the original order as they appear in the table. Only when I use Distinct does the data come out sorted; which flies in the face of "Distinct is unordered".
Unless SQL is sorting them, but you would think it would sort the data the same way even when Distinct is not being used.
If this was all being left up to SQL, DISTINCT in SQL doesn't auto order fields, so why would it get the request from LINQ and think it needs to sort the result set?
Wouldn't it treat the command to get distinct values as something it needs to translate into a SQL DISTINCT, which would mean no sorting?
(The table is currently filled with numeric values, so when I have values like 1-20, it will sort 1, 10, 11...2, 20, 21, etc.)