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 Query
- 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
- How do I return a new object from a mocked repository using a LINQ Expression?
- With LINQ how do you return a string const in the result from the select operator
- How to return data from two tables in one resource with Web API, MVC5 via Repository
- How to return a List(Of String) from a LINQ statement with a Group By in VB.net?
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- How to return anonymous type from c# method that uses LINQ to SQL
- How to insert a record with LINQ and C# and return the Primary Key of that record
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- How to get the latest date inserted from the table with Linq to entities
- How do I use Linq ToDictionary to return a dictionary with multiple values in the dictionary items?
- How to convert between Linq expressions with different return types?
- LINQ to Entities - How to return a single string value from entity
- LINQ method How to SelectMany with additional column from Parent class
- How to pass LinQ Expressions from F# to C# code
- How can I use linq to return integers in one array that do not match up with an integer property of another array?
- How does linq actually execute the code to retrieve data from the data source?
- how to get all columns from a linq result with a join
- How to return from ConditionalExpression.IfThen in tree with MethodCallExpression / lambda?
- How do you return certain properties from a linq query, rather than complete objects?
- How to return LINQ object from method?
- How to create a list from filtering 2 lists with linq to object
- how to get values from var-source with linq
- How to include one specific row from another table with LINQ to Entities
- How to access element from jArray with Linq
- How to return IGrouping from Linq query when grouping
- How to Bind Exclude more than one property from a model with linq to sql asp.net mvc
- Linq EF - How to gather all the accounts, cards, loans etc of a specific customer from database, with an optimized query?
More Query from same tag
- Finding objects in a collection that have any string from a list in a subcollection
- How to reformat Datetime when retrieving it from database using linq
- "ADD" to DataGridView from XML file
- how to efficiently Comparing two lists with 500k objects and strings
- LINQ to Entities does not recognize the method 'System.String PadLeft(Int32)' method
- How do I display a table to list using distinct?
- Need a performant way to return all duplicates from a list
- Get minimum and maximum time value from list of object property using Linq
- Iterate through LINQ AnonymousType object
- very slow C#/linq loop need improvement suggestions
- Should I return a null or an empty list?
- Where statement in a Linq request
- How to find an XML node that is missing a specific child node?
- Parse and add Elements to XAML using XDocument
- Linq, how can I do flexible sorting?
- Is it possible to implement RemoveAll() on EntityCollection<T>?
- Can I use a query designer to write Linq Queries against a DataSet
- LINQ SQL Query with a range variable and a constant
- LINQ WHERE clause equivalent in javascript
- Linq query with null check to get rows in different cases
- Convert advanced SQL query with nested joins to Linq-to-sql
- How do I grab only the latest Invoice Number
- LINQ Group By and merge properties
- Linq to entity framework error when using datetimeoffset
- Rationale behind renaming of higher order list operations
- linq as dataset issue with column names
- How can I use LINQ to match words
- c# linq join on a sublist in a list
- Return objects which contain Lists, based on the those lists matching
- Create XML file from collection list