Reputation: 83
Currently our DAL (Data Access Layer) queries the database and we loop through the resultant data to populate an object (one object per row) in which the final result is a List.
What is the most efficient (and quickest) way to populate the objects?
Which is the quickest way to get data out of the database and into a specific object designed for that result set?
This is C#
-- EDIT
By quickest, we mean the fastest for the computer to process, not speed of development.
This is also a .NET 2.0 application
--
Upvotes: 0
Views: 3222
Reputation: 14618
I believe the quickest (as in quickest to develop) is LINQ to SQL.
It does exactly that. Create classes that represent a list of attributes from each table. When accessing them, it retrieves data automatically from the database and populates these objects with data, which you can use then as a list of objects. It's all automated. You just write one single row of code for this, after you've made the mapping (dragged tables from the database to the Linq to SQL mapping)
The code can look as simple as this:
List<Something> yourList = YourAutomaticallyGeneratedDataContext.Something.ToList();
For Firebird, of course, LINQ to SQL won't work. Try Entity Framework instead. NHibernate is too much of a fuss, in my opinion.
But since you want the Quickest to process, I recommend you check out this site: http://ormbattle.net/ Choose your weapon, then fire. I am not considering the option with DataReader. It's a pain, and can lead to bugs. It's hard to maintain too.
Or, check this question, Best free ORM tools to use with .NET 2.0/3.5
Upvotes: 0
Reputation: 629
Most efficient is how you are doing using a forward-only SqlDataReader http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx
Requires plenty of "boiler plate" code however so not the quickest to write. I personally use NHiberate for that but that requires some learning http://nhforge.org/Default.aspx
Upvotes: 1
Reputation: 6085
There are a lot of ways to do this, depends on which version of C# you use.
You can use the following:
1. DataSet (.net 2.0 above I think?)
2. Linq2SQL (.net 3.5 above)
3. EntityFramework (.net 3.5 above)
For example of using Linq2SQL:
var result = (from t in YourTable
select t).ToList();
Upvotes: 1