score:2
Unless you go for simple classes (POCO etc), your own implementation is likely to have nearly as much overhead as DataTable
. Personally, I'd look more at using tools like LINQ-to-SQL, Entity Framework, etc. Then you can use either LINQ-to-Objects against local data, or the provider-specific implementation for complex database queries without pulling all the data to the client.
LINQ-to-Objects can do all the things you mention, but it involves having all the data in memory. If you have non-trivial data, a database is recommended. SQL Server Express Edition would be a good starting point if you look at LINQ-to-SQL or Entity Framework.
Edited re comment:
Regular TSQL commands are fine and dandy, but you ask about the difference... the biggest being that LINQ-to-SQL will provide the entire DAL for you, which is a huge time saver, as well as making it possible to get a lot more compile-time safety. But is also allows you to use the same approach to look at your local objects and your database - for example, the following is valid C# 3.0 (except for [someDataSource], see below):
var qry = from row in [someDataSource]
group row by row.Category into grp
select new {Category = grp.Key, Count = grp.Count(),
TotalValue = grp.Sum(x=>x.Value) };
foreach(var x in qry) {
Console.WriteLine("{0}, {1}, {2}", x.Category, x.Count, x.TotalValue);
}
If [someDataSource] is local data, such as a List<T>
, this will execute locally; but if this is from your LINQ-to-SQL data-context, it can build the appropriate TSQL at the database server. This makes it possible to use a single query mechanism in your code (within the bounds of LOLA, of course).
score:0
Why not use a local database like Sqlserver CE or firebird embedded? (or even ms access! :)). Store the data in the local database, do the processing using simple sql queries and pull the data back. Much simpler and likely less overhead, plus you don't have to write all the logic for grouping/aggregates etc. as the database systems already have that logic built in, debugged and working.
score:1
You'd be better off letting your database handle grouping, filtering and aggregation. DataTables are actually relatively good at this sort of thing (their bad reputation seems to come primarily from inappropriate usage), but not as good as an actual database. Moreover, without a lot of work on your part, I would put my money on the DataTable's having better performance than your homegrown data structure.
score:0
Yes, you can use LINQ to do all those things using your custom objects.
And I've noticed a lot of people suggest that you do this type of stuff in the database... but you never indicated where the database was coming from.
If the data is coming from the database then at the very least the filtering should probably happen there, unless you are doing something specialized (e.g. working from a cached set of data). And even then, if you are working with a significant amount of cached data, you might do well to put that data into an embedded database like SQLite, as someone else has already mentioned.
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- creating Linq to sqlite dbml from DbLinq source code
- Better code for avoiding one dictionary - Case Sensitivity Issue
- A Better DataTable
- Accessing a List multiple times in same code block - Any better approach?
- Is there a better way to get the column values from datatable
- source code for LINQ 101 samples
- How to code this LINQ query in a better way
- Is there a better way to code this LINQ fragment?
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Is there a better way to code this Duplicate ID Checker?
- Better Code in LinQ?
- Is there a better way to achieve this with Linq or a better code
- Better way to write this C# Code For List of Lists
- List or Array of String Contain specific word in Html Source Code
- Partition By Logic in Code to calculate value of a DataTable Column
- How to optimize a code using DataTable and Linq?
- c# Linq or code to extract groups from a single list of source data
- error :Could not find an implementation of query for source type datatable and join not found while trying to join two datatables
- LINQ query on a DataTable
- Is it better to call ToList() or ToArray() in LINQ queries?
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Is it better to use Enumerable.Empty<T>() as opposed to new List<T>() to initialize an IEnumerable<T>?
- Value cannot be null. Parameter name: source
- Filling a DataSet or a DataTable from a LINQ query result set
- Get all column names of a DataTable into string array using (LINQ/Predicate)
- How do I get a distinct, ordered list of names from a DataTable using LINQ?
- Linq code to select one item
- c# predefine LINQ select
- Execute stored procedure using entity framework
- Complex C# Linq Algorithm
- LINQ query Where ID does not exist as a property in a list of objects
- aggregation count in linq query returns null
- c# - Linq Error "Operator '==' cannot be applied to operands of type 'int' and 'System.Linq.IQueryable<T>" and RemoveRange
- Error Reading RSS Feed using LINQ to XML
- Entity Framework Include and Select are gettind some other entities
- Linq Get next n records
- Using a Singleton pattern to Linq to Sql Data Context
- Merge Rows in List. if one column has different values
- SQL LIKE in Linq
- Getting the first result from a LINQ query - why does ElementAt<T>(0) fails when First<T>() succeeds?
- Join 2 table and group 2 field in linq
- vb interfaces with linq-to-sql
- LINQ: Combining vectors
- Can't Get Count of More than one table fields Through Linq Query
- How to convert complex query to Model in a LINQ to Entities query
- Linq repository vs dbcontext bring different result the same query
- Return Enum Name from Integer in LINQ Database Query