c# - Entity Framework 5 - Local BindingList - Filtering? -


hopefully can point out how this:

i have winforms application uses entity framework. e.g. have data bound gridcontrol via repository delivers bindinglist.

e.g. (simplified code)

class productrepository {    public void loadall() {            _context.products.where(p => p.deleted == false).load();    }     public bindinglist<t> getbindinglist() {            loadall();            return _context.products.local.tobindinglist();    } }  class productlistpresenter {     private void setlist() {        _view.setlist(productrepo.getbindinglist());     } }  class productlistview {      deletedbutton.click += {          (bindingsource1.current product).deleted = 1;          gridcontrol1.refresh();      }; } 

but: want display non deleted products (product.deleted == false). okay filter within repository load() method, how filter when bound control? can't bindingsource1.removecurrent() wipe entity , mark state.deleted..

another thing consider here is: have other things going on in form , need changes committed in database when user decides save changes clicking on "save"-button. kind of have work in memory state until user explicitly saves changes.

any suggestions? using ef in winforms somehow starting raise frustration level..

because deleting logically rather physically need bubble delete event through layer has access repository or context, save change , detach entity context. example:

class productlistpresenter {      private void deletehandler(object sender, eventargs e)     {        productrepo.savechanges();        productrepo.detachlogicallydeletedentities();     } }  class productrepository  {   public void detachlogicallydeletedentities()   {    foreach(var entity in _context.products.local            .where(p=>p.deleted == 1).tolist())                _context.entry(entity).state = entitystate.detached;    } } 

if undesirable option not bind context local collection independent bindinglist<> , can remove list directly in view layer.

class productlistview {      deletedbutton.click += {          (bindingsource1.current product).deleted = 1;          bindingsource1.remove(bindingsource1.current);      }; } 

a third way create implementation of ibindinglistview holds , caches context local observablecollection<> , provides layer of indirection between local collection holds provided display. way use bindingsource.filter property provide filter string.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -