c# - MVVM: Loading large data records -
as i've learned mvvm pattern there observablecollection in every viewmodel holds models. have viewmodel implemented this:
public class viewmodel { public void loaddata() { items = new observablecollection(_logic.select()); isdataloaded = true; } }
let's _logic.select()
returns list<>
of records in table. if data large? if have thousands or maybe hundred thousands of records in table? should load them in observablecollection
? takes lot of time them loaded.
you shouldn't load data database, load need. think how badly hurt performance load 1000 registries if need one:
you need query db. use server create , execute query , keep data somewhere, in memory. send client. client need keep data somewhere.
as said before, can use server side paging and/or filtering.
the logic simple, on server have "return myentity;" or method that.
instead of doing it, why not implement "take" extension method provided linq.
edit:
that post covers more paging, pay special attention to:
public ienumerable<superemployee> getsuperemployees(int page) { using (var context = new northwndentities()) { var q = context.superemployeeset.orderby(emp=>emp.employeeid).skip(page * pagesize).take(pagesize); return q.tolist(); } }
check qhe value of "q" uses skip , take method go specific item , there, take x amount of them.
finally, sorting similar code above, more complex. can use method linq implement it.
Comments
Post a Comment