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>.


Related Articles