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:

found example: http://blogs.msdn.com/b/brada/archive/2009/07/17/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-8-wcf-based-data-source.aspx

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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -