DataReader or collection of entities

  • Thread starter Thread starter Andy B.
  • Start date Start date
A

Andy B.

I am writing the DB access layer of my web application. I am working on the
News section and have an entity called NewsArticle. When I return multiple
rows from the database, is it better to bind a datareader to databound
controls or is it better to make a collection of NewsArticles and bind the
databound controls to that?



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4022 (20090420) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
My opinion is that its better to use the IDataReader just as fast as you
can.

Which would be putting them into simple objects.

And send those objects (collection of them) up to the presentation layer.
 
Andy said:
I am writing the DB access layer of my web application. I am working on the
News section and have an entity called NewsArticle. When I return multiple
rows from the database, is it better to bind a datareader to databound
controls or is it better to make a collection of NewsArticles and bind the
databound controls to that?

You use the a datareader and you use DTO(s) Data Transfer Objects and
bind them to a control such as a datagrid with a List<t>.
 
I am writing the DB access layer of my web application. I am working on the
News section and have an entity called NewsArticle. When I return multiple
rows from the database, is it better to bind a datareader to databound
controls or is it better to make a collection of NewsArticles and bind the
databound controls to that?

Assuming you are using Linq, it's best to bind an IEnumerable<NewsArticle>
or IQueryable<NewsArticle>. By doing this, the database won't be queried
until the collection is actually enumerated. This allows you to take your
result and pass if through further queries if you need to filter the results
first. Additionally, paging will be automatically implemented in the
generated SQL if you use the paging features of databound controls.

Pete
 
Back
Top