c# - EF Don't save using IQueryable in BindingSource -
i've created code first context dbset property
i work windows form. if bind follow:
_context.schedules.load(); schedulebindingsource.datasource = _context.schedules.local.tobindinglist();
all works great , when save follow:
this.validate(); schedulebindingsource.endedit(); _context.savechanges();
the data persists; when bind data this:
var res = _context.schedules.where(k => k.employeename.equals(employeecombobox.text)).tolist(); schedulebindingsource.datasource = res;
when save data doesn't persis!
i'm thinking tolist() method not good, can't find alternative bindinglist connected local set of data inside context.
thanks,
andrea
you can try this:
_context.schedules.where(k => k.employeename.equals(employeecombobox.text)).load(); schedulebindingsource.datasource = _context.schedules.local.tobindinglist();
that should bring schedules meet condition. when call load
method after where
method, going bring memory records meet condition. later, when call local
property,it give observablecollection<schedule>
contains objects tracked dbcontext
thy going elements loaded before. @ end, when call tobindinglist
extension method, returns bindinglist<schedule>
stays in sync given observablecollection<schedules>
.
Comments
Post a Comment