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 Query
- 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
More Query from same tag
- How to get second and third rows using Entity Framework
- LINQ query depending on grandchild collection
- C# aggregate in a better time complexity
- Linq Method for Intersecting with a Condition
- Multicolumn LIST<T> - Finding duplicates of a one column based on another column
- Operator '!=' cannot be applied to operands of type 'bool?' and 'int'
- Delete outer xml node without deleting inner xml
- What is the difference between a regular foreach and ForEach LINQ operator when it comes to async/await
- Converting nested collection into flat Data Table
- C# : Parse XML using XDocument into a csv file
- How to return list from linq query using viewmodels
- How to filter SelectList with linq
- Using LINQ how do I have a grouping by a "calculated field"
- LINQ Grouping Data Twice
- Query xml file without loading it into memory?
- What exactly is a circular reference?
- How to a List using LINQ Query?
- EF6 Linq query for joining tables with view model
- Getting all objects from all IEnumerables within all IEnumerables
- C# Linq multi-word search
- Converting C# Expression Parsing to F#
- Order by then count and select Max by group, performance issue
- Entity Framework: Any or All - Unable to create a constant value of type 'System.Collections.Generic.List`1'
- Get all the child details in a xml?
- Datatable.GetChanges() always returns null
- LinqToSql query execution timing
- Trying to map a property of an object to a string with AutoMapper
- Assigning values to a public property not working if other class properties are set by results from a database
- converting into string in linq to entites
- Fail to convert LINQ query result to ToList