Filtering in collection or data storage?

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 06-May-2010 23:24:14   

Hi, here is my case: trying to create the schedule table for a student. i have a view that holds studentid, periodid, day, class

a regular student has 35 to 40 entries in this view.

what i do now is; create a new schedule typed view, filter it by studentid, periodid and day. and show the class info in a grid cell for the appropriate period and day.

this method makes 35-40 visits to data storage which i believe isnt very good. what would be a better approach?

maybe getting all entries for the student at once as a schedule typed view and filter it by period and day (if this is possible)?

or maybe something totally different than what i ve been doing?

thanks in advance

-shane

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 07-May-2010 01:04:45   

When you say you "filter" the schedule typed view, do you do this on the server in the sql query when the view is fetched, or on the client side when you have fetched the entire view ?

And in any case, how does it end up making 40 visits to the database...?

The most efficient way to retrieve this is to retrieve the view using the appropriate predicate expressions so that the filtering is done on the database (they're good at this sort of thing simple_smile )

Matt

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 07-May-2010 12:52:45   

MTrinder wrote:

When you say you "filter" the schedule typed view, do you do this on the server in the sql query when the view is fetched, or on the client side when you have fetched the entire view ?

And in any case, how does it end up making 40 visits to the database...?

The most efficient way to retrieve this is to retrieve the view using the appropriate predicate expressions so that the filtering is done on the database (they're good at this sort of thing simple_smile )

Matt

i do it on the server since i go cell by cell in schedule. looking for the first period on monday for student A and getting his class, next looking for second period on monday for student A etc. this happens for every single cell in schedule (35 to 40 cells)

i can get the entire schedule for the student which will bring back 35-40 entries. then do i loop through every item of the typed view to find the period/day match? would this be more efficient?

-shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-May-2010 02:18:48   

Instead of looping you can create different views (filtered and sorted) of the same data. Please read about EntityViews.

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 10-May-2010 06:40:46   

daelmo wrote:

Instead of looping you can create different views (filtered and sorted) of the same data. Please read about EntityViews.

not sure if i get you.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-May-2010 06:48:13   

It's about what you said:

e106199 wrote:

i can get the entire schedule for the student which will bring back 35-40 entries. then do i loop through every item of the typed view to find the period/day match? would this be more efficient?

Indeed you can get the entire schedule, then you can create filtered in-memory views that you can use to show only the info you want, without affecting the original collection. EntityViews will help you on that.

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 10-May-2010 07:27:48   

daelmo wrote:

It's about what you said:

e106199 wrote:

i can get the entire schedule for the student which will bring back 35-40 entries. then do i loop through every item of the typed view to find the period/day match? would this be more efficient?

Indeed you can get the entire schedule, then you can create filtered in-memory views that you can use to show only the info you want, without affecting the original collection. EntityViews will help you on that.

ok so that ll be like querying the schedule typed view which is now in memory. but dont u think that i still have to do it the number of cells i have in schedule? is it like querying against the database vs querying against the returned typed view?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 10-May-2010 10:40:49   

is it like querying against the database vs querying against the returned typed view?

Yes, but there is no clear answer here on which is better. It depends on what is more critical to you, or what costs more (speaking about performance)?

If this is a web application and the database resides in the same server, then maybe 35 to 40 calls won't hurt the performance, taking into consieration that the student might not navigate to his entire schedule. Thus most probably you will end up with much less database calls. And you will save some memory, because you won't end up loading the entire schedule for every student acessing the server at the same time.

If this is a desktop application and the database calls consumes some time for the round trip, then maybe it's better to fetch the entire schedule and filter it on the client side, as the student navigates through his schedule.