c# - Entity Framework SaveChanges() not reflecting on entities -


i have winforms project , database running on sql server has 2 tables, student , standard.

first created ado.net entity data model database wizard thing. have datagridview control has bindingsource datasource.

note: databindingprojection class created able populate datagridview properties both student , standard entities

i have code:

var query = context.students                   .include(s => s.standard)                   .select(s => new databindingprojection                   {                       studentid = s.studentid,                       studentname = s.studentname,                       dateofbirth = s.dateofbirth,                       height = s.height,                       weight = s.weight,                       standardname = s.standard.standardname,                       standard_standardid = s.standard.standardid                   }).tolist();              mylist = new bindinglist<databindingprojection>(query.tolist());             databindingprojectionbindingsource.datasource = mylist;             databindingprojectiondatagridview.datasource = databindingprojectionbindingsource; 

the grid populated however, when call context.savechanges(), doesn't update database.

using select method on dbset project data non-entity class destroy link original data. in case, should bind student class directly.

to bind properties in standard class, can extends student adding property because partial class.

partial class student {     public standardname {         { return this.standard.standardname; }        set { this.standard.standardname = value; }     } } 

assuming standard property never null.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -