score:3
Accepted answer
Adding OrderBy
(like any of the other query functions) turns your query into an IQueryable<TEntity>
. Fortunately, LINQ-to-SQL's internal query type (DataQuery<TEntity>
) provides a BindingList<TEntity>
via its implementation of IListSource
.
To get a BindingList
for a given query, you can do this:
var bindingList = ((IListSource)query).GetList();
In your case:
d.tbUser = ((IListSource)context.Users.OrderBy(x => x.Name)).GetList();
While the return type of GetList
is IList
, it is, in fact, an actual BindingList<User>
.
Source: stackoverflow.com
Related Query
- Linq SQL error with one-to-many relationship and orderby complex expression
- SQL subquery result in LINQ and Entity Framework Code First
- OrderBy, GetNewBindingList and Linq to SQL
- Paging API calls using Linq to Sql OrderBy with string parameter and reflection
- Condition based Linq to SQL OrderBy and ThenBy
- LINQ to SQL GroupBy, Take and OrderBy
- Optimise and speed up very slow Linq / SQL code
- Creating Linq from SQL with OrderBy and GroupBy
- How to write SQL translateable linq code that groups by one property and returns distinct list
- LINQ to SQL using GROUP BY and COUNT(DISTINCT)
- How are people unit testing code that uses Linq to SQL
- LINQ to SQL and a running total on ordered results
- Odd behavior in LINQ to SQL with anonymous objects and constant columns
- Translate SQL to lambda LINQ with GroupBy and Average
- How to Convert Row to Column in Linq and SQL
- Linq To SQL and Having
- OrderBy and Top in LINQ with good performance
- LINQ to SQL in and not in
- Linq to SQL using group By, and order by count
- LINQ : Distinct and Orderby
- LINQ - writing a query with distinct and orderby
- Simple sql to Linq query with group by and aggregate functions
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Linq "Could not translate expression... into SQL and could not treat it as a local expression."
- Separating concerns with Linq To SQL and DTO's
- LINQ to SQL - How to efficiently do either an AND or an OR search for multiple criteria
- EF and Linq OrderBy using two Parameters
- LINQ to SQL *compiled* queries and when they execute
- How to intercept and modify SQL query in Linq to SQL
- SQL Query to LINQ syntax using not exist and join
More Query from same tag
- LINQ order by local list
- beginner Linq syntax and EF4 question
- LINQ - Multiple left joins with nullable values
- LINQ to SQL cross apply
- Reducing Memory Footprint
- LINQ find records with no join
- Ordering list<T>
- Why this Linq is returning null?
- Using LINQ expressions in Visual Studio's Watch window
- Dotnet EF Core 2.1 throws QueryClientEvaluationWarning when querying decimal property
- sort string array using LINQ
- Concatenating two sequences with their elements interleaved
- LINQ Contains Based on Property
- Problem in calculating statistics using group by based on statuses
- The model on a view is null when using RedirectToAction
- Writing dynamic LINQ queries as closure methods
- Sort list of lists using LINQ so high score is first then lastname and firstname in alphabetic order
- Sorting an XElement
- How to work with Aggregate function in LINQ with join
- dynamic linq query - OrderBy with properties that are null
- How do I use LINQ group by clause to return unique employee rows?
- How to add range of collection to other collection?
- Linq Query : Cannot convert type IEnumerable<string> to string changing .ToString() to (string)
- How can ı remove from duplicated items in C#?
- return from a linq where statement
- Sorting XML with Alphabetic and numeric (code="BC1")Attribute in C#
- LINQ - Does the Where expression return new instance or reference to object instance
- Entity Framework - Linq - Comparing Nullable objects - NotSupportedException
- ASP.NET / LINQ / EF: Async on custom distinct comparer class
- .NET and Hadoop - What should I know / learn and what is available?