Monday, March 26, 2012

Performance: Custom Collections?

There used to be a performance subforum somewhere around here, but I don't seem to see it anymore.

Anyway, I'm still rather new to .NET 2.0, and was wondering if the best(in terms of performance) way to retrieve, and display data from a database is by using custom collections? I recall how slow Datasets used to be in 1.1. I've also read that datasets are much faster now in 2.0, can someone clear this up for me?

Well, "it depends"...

If you are reading from the DB odds are you are already getting dataset(s) so if you have to put it into an object collection it's an extra step, so theoretically its slower... odds are though you'll never notice. Object are the way to go if you can, WAY more options in dealing with it/them.


Hmm, so it's slower? I remember seeing it under one of MS's best practice, during the .NET 1.1 days..

It is a hard question to answer. But you populate the collection using a DataReader so it is pretty fast but on the other hand you populate the DataSet using SqlDataAdapter which behind the scenes calls the DataReader. The main difference comes when you are transfering the data back and forth specially in the case of web service. DataSet is a pretty heavy object since it contains so many different kind of objects. Also if you are using entity classes it will give you more clarity in the code and you will be able to use the object oriented features. Typed DataSet is pretty close to entitty class since it gives you strong type but in the end it is still a dataset and heavier then the entity class.


Ok, thanks for the reply. I'll go read up more on the new functions .NET 2.0 has and post back with more questions. So, entity classes still processes faster than datasets or any of the new methods(if any?) in .NET 2.0?


Are there any new techniques in populating data into a datagrid or something, without the use of a typed dataset in .NET 2.0?


So, if it's not necessary for me to pass my data(datasets) through pages, it'll be "OK" to use datasets for that scenario?


Um.. bump, and also to post another question: does anyone have the link to an article at msdn that introduces custom collections, I remember coming across that link, but I can't seem to find it now. Any other links related to custom collections, passing objects(not dataset) through tiers are also welcomed :)

First here is a link to the article on msdn:

http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/CustEntCls.asp

Now for your question. Yes, you can populate the Datagrid, GridView controls using the custom collections. All you need to do is assign the GridView.DataSource = (List of objects)

List<Person> persons = new List<Person>();

You will have to read something about Generics and Generic collections.


Thanks for the link.

I've come across this new class called the ObjectDataSource, I've searched it up on msdn, and have read about it in a few books, but I'm still not quite sure what it actually does, could anyone enlighten me? If I'm populating a datagrid via the custom collections method, how will this ObjectDataSource play a part in it?

0 comments:

Post a Comment