score:1
Accepted answer
I believe the problem is caused by way LinqPad is creating the DBContext (or whatever it does internally) when you query a database directly (as opposed to creating your own EF connection). If I run this:
using (var context = new MyContext()) {
var query =
from x in context.MyTable
select new {
x.ID,
g = Guid.NewGuid()
};
}
I get the following SQL
SELECT
[Extent1].[ID] AS [ID],
NEWID() AS [C1]
FROM [dbo].[MyTable] AS [Extent1]
Which results in a unique guid for each row. You can alter the Linq to orderby Guid.NewGuid()
and you'll get the random sorting that you want.
var query =
from x in context.MyTable
orderby Guid.NewGuid()
select new {
x.ID
};
Source: stackoverflow.com
Related Articles
- Sort by New Guid for random order
- Trying to get a random sort order
- Linq order by random without GUID
- C# - code to order by a property using the property name as a string
- Better way to sort array in descending order
- linq: order by random
- Conditional "orderby" sort order in LINQ
- LINQ and a natural sort order
- passing dynamic expression to order by in code first EF repository
- Why does using Random in Sort causing [Unable to sort IComparer.Compare error]
- Sorting a generic list by an external sort order
- Sort part of a list in descending order (by date), the other part in ascending order (alphabetically)?
- How to get Swedish sort order for strings
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- Modifying the sort order of a LINQ query
- Order of List using Linq is not the same as sort
- Order by sort order that is greater than 0
- Sort the SQL Query in the order of IN
- DataContext.CreateDatabase is creating the database with columns in random order
- How can I sort my string array from .GetFiles() in order of date last modified in asp.net-webpages?
- Linq (or SQL): Get a search query and sort it order by best result
- creating Linq to sqlite dbml from DbLinq source code
- SQL RANDOM ORDER BY ON JOINED TABLE
- IList with an implicit sort order
- Order a List by a arbitrary sort expression?
- LINQ: Sort records in ascending order with NULL values last
- Adding a random Guid column to a Linq to Entities query to grab random records
- Sort list and select object based on order by
- Why EF can't sort items by the order of another collection and how to workaround?
- How to use Dapper LINQ with TableDirect (without embedded SQL) with ORACLE?
- SQL ROW_NUMBER() in LINQ Query Syntax
- Match and Map fields from two lists LINQ
- ContainsValue VB
- how can i add source node as child node in project?
- How to join table in LINQ and return list in MVC
- Concatenating LINQ query results when using loops
- Prevent repetition
- What's the difference between FindAll and Select?
- Defining comma separated strings in EF and using with Linq
- LINQ select distinct, multiple columns
- Passing Func<> to IQueryable vs Expression<Func<>>
- How to generate a full dynamic grid with Linq and JQuery DataTable?
- LINQ to SQL Custom Property query on where clause
- loading related entities
- A Shortcut for c# null and Any() checks
- How can I group by a distinct list?
- Linq - How to exclude items from autocomplete array
- Multiple on clause in LINQ to DataTable Join Query
- Save a file from SQL Database on button click using Linq in ASP.NET