c# - Designer Issue + Entity Framework (WPF MVVM) -
background, wpf project uses entity framework when run works fine, designer gives following error.
unhandled exception specified named connection either not found in configuration, not intended used entityclient provider, or not valid.
i have coped connection string ui still problem
i have following binding
datacontext="{binding source={x:static viewmodel:viewmodellocator.mainwindowviewmodelstatic}}"
which relates class initialises
new mainwindowviewmodel(new uidataprovider());
which has following
private readonly iuidataprovider _dataprovider; private ilist<customer> _customers; public ilist<customer> customers { { if (_customers == null) { getcustomers(); } return _customers; } } public mainwindowviewmodel(iuidataprovider dataprovider) { _dataprovider = dataprovider; tools = new observablecollection<toolviewmodel>(); tools.add(new atoolviewmodel()); tools.add(new btoolviewmodel()); } private void getcustomers() { _customers = _dataprovider.getcustomers(); }
the designer instantiates code @ design time. code is, upon instantiation, attempting access data, , entity framework code looking in wrong place connection string. solution not @ design mode.
the naive method check designerproperties.getisindesignmode. isn't mvvm, have check in view model, , injects ui code view model.
what's solution? can hold nose , (quick , dirty), create inject-able interface abstracts check viewmodel, by-default implementation checks dependencyproperty, or catch exception , swallow gracefully.
Comments
Post a Comment