c# - Entity framework. Reloading local data -
i have control in wpf app binds property
public observablecollection<entity.account> accounts { { _context.accounts.load(); return _context.accounts.local; } }
i expected every time control reaches data, local collection gets reloaded scratch database because of load() method, apparently wrong.
so have 2 questions: load() if it's not loading entities context local? , how can populate local collection other means load()?
more details:
first here's how it's bound:<textbox text="{binding name}"/>
, in code-behind datacontext = _viewmodel.accounts;
this accounts property 1 wrote above. , name propery binds part of account entity.
if edit account's name , won't call entitycontext.savechanges() change in local collection won't change in database , calling load() method won't refresh local collection. refreshes when program restarts (when context created anew)
what load() if it's not loading entities context local?
the load extension method on iqueryable enumerates results of query. equivalent calling tolist without creating list. read here msdn
how can populate local collection other means load()?
do mean refresh? if yes can use reload reload entity database overwriting property values values database. as:
foreach (var entity in _context.changetracker.entries()) { entity.reload(); }