Hello,
Does SqlDataReader fetch one record at a time from DB or one field at a time?
Assume the following query returns a single row:
select columns_1, column_2, column_3
from some_Table
and suppose readerS ( readerS is an instance returned by SqlCommand.ExecuteReader() )only reads *column_3* before closing the connection:
readerS[“column_3”].ToString();
Now will readerS fetch from sql server just a *“column_3”* value, or will it fetch all 3 columns, even though it will only read one?
Reason I’m asking this is because I’m currently reading a book on website programming and author mentions that he will code DLL objects to use lazy load pattern.
In short - when DLL object is created, a DB query is performed (via DAL), which retrieves data from various columns and with it populates the properties of our DLL object. Since one of the fields ( call it "L" ) may contain quite a substantial amount of text, author decided to retrieve that field only when that property is read for the first time.
But when I looked at stored procedure used by author to retrieve columns and populate DLL object's properties ( except for property L, which won't get populated ), I've noticed that procedure also retrieved L column, even though it won't be used to populate a corresponding property. Now if DataReader retrieves a whole row, and not just the field we actually read, then author didn't really implemented lazy load pattern?!