Which one is best for your circumstance? Or, more importantly, does the speed difference for the amount of data you're querying make it worthwhile to choose one over the other?
LINQ is generally easier to read, on my opinion, than pretty much any other form of data filtering and has the advantage over using
DataTable.Select of being, at least partially, strongly-typed making it harder to make mistakes.
// Using DataTable.Select() DataRow records = myTable.Select("(MyIntField > 30 AND MyStringField == 'StringValue') OR AnotherField > 70"); // Using LINQ var records = from record in myTable.AsEnumerable() where (record.Field<int>("MyIntField") > 30 && Record.Field<string>("StringValue") == "StringValue") || (record.Field<int>("AnotherField") > 70) select record;
The LINQ query is bigger, but personally I think it's more readable
If u want faster execution then Datatable.Select() or you can go for LINQ
Which one will be the fastest? Only you can say.
- What's the amount of data
- How many records are returned
- How do you intend to use the result e.g. will you always use every record in the result?
- What's the complexity of the filter
All those can impact which solution will be the fastest. As always if you do not have a performance problem, don't optimize. If you do have a performance problem then use a profile to find out where to optimize.
If you do not have hard evidence that the select is a performance problem go for readability. That in my mind translate into the LINQ solution.
- Linq code to select one item
- Linq : select value in a datatable column
- Select distinct rows from datatable in Linq
- select object which matches with my condition using linq
- count VS select in LINQ - which is faster?
- DataTable Select vs LINQ Select
- LINQ Select DataRow from DataTable
- LINQ Source Code Available
- Which LINQ query to select rows from 1 table that are not in another table
- LINQ Select From DataTable
- DataTable select with LiNQ and check is there duplicate rows or not
- Linq not in select on datatable
- LINQ Select distinct on DataTable not working
- LINQ DataTable Select Distinct Rows
- DataTable Select vs List<T> LINQ Performance
- How to select all columns in LINQ Datatable join?
- Which way is better Linq Select Query or For Loop to search something in generic List?
- LinQ query select DataRow from DataTable
- creating Linq to sqlite dbml from DbLinq source code
- How to select multiple columns from datatable in linq group by?
- NHibernate LINQ query performance, which code fragment is better?
- generic method to get linq result to datatable for select new with multiple selects
- Avoiding duplicate code in Linq Select method
- select case in Datatable datarow in Linq
- Building which properties to select with LINQ To Object
- C# Linq How to select the distinct row count of multiple columns in a datatable
- Datatable LINQ select datarow only returning one row and how to order
- LINQ Select Modified Version From Datatable
- Select List of Object Which Contain Another List by LINQ
- How to Select top (5) contributors group by Business type code in c# linq query
- Select last wrong item from the list
- Linq union two tables where on has an extra column
- Exception creating JSON with LINQ
- Linq How to Join and get 2 tables values
- Dynamically sort with linq C#
- Reference to a property of class in predicate using reflection
- Migrating vs2008 to vs2012 - Exception LINQ to SQL Library
- get all the children whose grandparent's ID is equal to 1
- Linq Basic Query
- Linq issues, joining two tables and a collection
- How much of a performane hit will i take from casting when trying to make this code mistake proof?
- C# LINQ - Group List by a property then select by different groups
- Entity Framework projection behaviour
- At least one object must implement IComparable calling OrderBy()
- How to return linq query into single object
- Lambdaexpression of Linq-query in a variable
- How to include empty string as a group in group by in linq?
- Combine property selector expression tree and value to create a predicate for EF filtering - create filter from lambda selector and value
- Is there a way to get the SQL created by a LINQ query?
- LINQ returns different sort order for same function