score:3
You can use
var Result =
from a in Db.Table
select a;
var ResultSorted =
from a in Result
orderby a.Field
select a;
foreach(var RowSorted in ResultSorted)
{
MessageBox.Show(RowSorted.ToString());
}
Edit: The thing is that
select new {TableData = a};
creates a new anonymous type with a field called TableData, like this
class Tmp1
{
TableType TableData {get; set;}
}
and
select new {All = a};
creates a new anonymous type with a field called TableData, like this
class Tmp2
{
Tmp1 All {get; set;}
}
Edit 2:
If you select a
directly you don't create the extra anonymous type, instead you return the TableType
.
score:0
var ResultSorted =
from a in Db.Table
orderby a.Field
select a.ToString();
Edit: Fixed, didn't see the first query. This should be identical now. There is no need to create anonymous objects all the time.
score:0
You are returning a new instance of an anonymous type in each of your LINQ queries:
select new {TableData = a};
select new {All = a};
What you are saying to the compiler is (in the first LINQ query), "Give me a new instance of an anoymous type. I want this anonymous type to have one property named TableData
and I want the value for that property to be a
."
If you simply return a
instead of an anoymous type, you shouldn't need to go through the properties of the nested types to get the data. Try this:
var Result =
from a in Db.Table
select a;
var ResultSorted =
from a in Result
orderby a.TableData.Field
select a;
foreach(var RowSorted in ResultSorted)
{
MessageBox.Show(RowSorted.ToString());
}
Source: stackoverflow.com
Related Articles
- Question About Querying Linq Results
- LINQ Source Code Available
- NHibernate querying on a string collection using Linq results in either error or empty collection
- LINQ query returns old results when source list is re-initialized
- LINQ - Querying about 6000 unique records by WHERE clause
- LINQ to Entities question about orderby and null collections
- My question is about comparing List<string> with Dictionary <string, List<string>> using C# linq
- creating Linq to sqlite dbml from DbLinq source code
- question about linq select and ToList()
- C# LINQ question about foreach
- Querying with LINQ basic question
- Basic question about OOP Class Structure with LINQ
- Question about length of an object in LINQ
- source code for LINQ 101 samples
- c# linq question about multiple where clauses
- Different results LINQ vs 'normal' C# code
- LINQ querying results for a decimal sum between two dates
- LINQ Select: different projects same code different results
- How to dynamically create linq code at runtime and get results
- LINQ - Entity framework code first - Grouped results to custom class
- Question about Linq
- Simple LINQ question about Any()
- Question about LINQ and Lambda requery
- Linq question about grouping something that can change?
- c# Linq or code to extract groups from a single list of source data
- Querying external data source with LINQ
- Querying the database using EF Code First and Linq
- Linq and EF: Querying to get results on one to many relationships: Selecting table with foreign Key
- What does LINQ return when the results are empty
- Convert string[] to int[] in one line of code using LINQ
- Convert RowData into GridView Columns through LINQ
- How do you do complex "OR" filters at the database level in Entity Framework?
- How to configure mvc mini profiler with Linq to SQL?
- Where does LINQ overload Console.WriteLine() for it's IEnumerable<T> result
- C# linq to json how to read a property value within a Array
- passing list to linq query
- Linq distinct doesn't call Equals method
- Simple update with Entity Framework
- Entity Framework Code First - Maintain a Long connection to Database
- C# lambda expression in LINQ query
- Need help understanding unexpected behavior using LINQ Join with HashSet<T>
- How to delete a row in datatable using linq to dataset?
- How do I use LINQ with GROUP BY and multiple MAX(...) to select multiple fields?
- How could I use linq when calculating a answer from a symbol and two numbers
- Group by for list in list
- Append IQueryable with additional query parts
- Order by from another context
- How to map a default LINQ expression in a generic class
- Get results of group by and add to multiple lists c#
- LINQ statement getting value from one table depending on the other table