DataReader or collection of entities

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
 
S

sloan

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.
 
M

Mr. Arnold

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>.
 
P

Pete Hurst

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top