score:2
This for instance works and it sorts and returns an IList<T>
:
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string City { get; set; }
}
public IList<Customer> GetSortedListOfCustomersInCity(string city)
{
return context.Customers
.Where(c => c.City == city)
.OrderBy(c => c.Name)
.ToList();
}
(I think this is also what Reed Copsey in his answer meant.) I guess, your problem is of another kind, since it is too obvious that this example works. But I couldn't derive from your questions where exactly your issue is. A piece of your not working code is appreciated.
score:1
So my question is what do I from here? All I want to do is return data to the client (in this case the services), in an ordered fashion without changing return types all the way through my application.
When you create your queries, you can always return results.ToList()
, which will evaluate them and convert them into an IList<T>
for you.
This is, in many cases, advantageous if your query is an IQueryable<T>
internally in any case, as it will fully evaluate the query, and prevent issues that can arise if you close your internal data context, then try to enumerate your results.
Source: stackoverflow.com
Related Articles
- How to return IList from my repository with ordered queries in LINQ/EF
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How to Deal With Dapper return Key Value pair with Dynamic from LINQ
- Inconsistent return types of linq queries with orderby clauses
- Linq to return a new object with a selection from the list
- Using Linq to return the count of items from a query along with its resultset
- creating Linq to sqlite dbml from DbLinq source code
- Linq sub query when using a repository pattern with EF code first
- Return List<Object> from Linq SQL (Lambda) with join and where
- LINQ - Return Value From Field With A Max Value if No Rows Found
- Can't add a new record with an integer value into database by using linq from code C#
- How do I return a new object from a mocked repository using a LINQ Expression?
- Need "Method return type" of data selected with LINQ from DataTable
- With LINQ how do you return a string const in the result from the select operator
- Generate Multi-Parameter LINQ Search Queries with Run-time Specified Return Type
- How to return data from two tables in one resource with Web API, MVC5 via Repository
- Return data from related records with Linq to Entities
- How to return a List(Of String) from a LINQ statement with a Group By in VB.net?
- return a list of objects ordered by number of items in navigation property with linq to entity
- c# Linq or code to extract groups from a single list of source data
- Is it possible to combine 2 view models, each populated with 2 different LINQ queries and return to 1 view?
- Linq join on multpile columns with a where not equals condition and need to return columns from both tables
- Using a list of Json results as parameters for a mvc actionresult, to return objects from database with Linq and Lambda
- A problems with display data from linq queries in grid
- Find a certain value from a source collection in a target collection of different type with linq
- Entity Framework dynamic linq where from generic source with dynamic where clause
- Linq return 2D array with index from string splitting
- Return Rows with Unique and Duplicate values from dataTable using LINQ
- Create a list from two object lists with linq
- LINQ query to return distinct field values from list of objects
- How do I get a complete list from a XML-file by using LINQ?
- EF Linq Product Sum when no records returned
- How do I use linq within a loop?
- Dynamic Linq to Datatable Nullable Fields
- Check if there's a open connection to database asp.net/c#
- prevent duplicates items listview form listbox asp.net mvc3
- Order of select-from-where in LINQ is changed? What is the reason?
- How To Compare Table With Datatable or Datable A with Datatable B and update Table by c#
- How to make a LINQ Statement on many-to-many tables?
- Slow LINQ query because of Where+ToDictionary
- Performance tuning C# permutations and SHA1 code
- format datetime from linq query into selectlist for dropdown
- ASP.NET MVC LINQ GroupBy differs from SQL Server GroupBy?
- ASP.NET LINQ query for filter and loop through multiple tables
- How does OrderBy in LINQ work (behind the scenes)?
- Grouping by interval with NHibernate QueryOver
- How to fill ListBox with data entries programatically in Silverlight?
- Emulating a join which uses a contains operator opposed to equals?
- Linq At least one object must implement IComparable
- Help with recursive linq expression