Selecting one field only

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 10-Dec-2010 09:05:36   

Hi, i have an academicterm table with the following fields: termid, startdate, enddate,termname, semesterid

i would like to get the semesterid of a term that is filtered out using a date parameter. so user selects a date and my method finds the term that holds the selected date and returns its semesterid.

i did it by running a getmulti with startdate <= date and enddate >= date filter on academicterm collection. then i ve selected the 0. index of whatever gelmulti has returned as an academictermentity and returned its semesterid value.

i wonder if there is a better way to this. maybe getscalar?

or do you think what i ve done is the proper way?

thanks -shane

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Dec-2010 09:31:49   

What you have done is not wrong, and indeed you may use GetSScalar().

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 10-Dec-2010 09:57:35   

Walaa wrote:

What you have done is not wrong, and indeed you may use GetSScalar().

thanks but what i wanna know is which was is preferable here?

since all i need is one field do you think getscalar would be better here or getscalar isnt exactly for this so getting the first entity of the collection than returning its semesterid (what i ve done now) would be a better approach?

it is not that i am asking how, its more like which one?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Dec-2010 10:27:55   

You can examine both generated SQL queries, to find out which one is better for you.

But in general GetScalar should be better as it is returning one value, and so you will avoid any entity/collection plumbing overhead.