c# - EF primitive properties not mapped even though are persisted in DB -


i have following class:

 public class mymodel     {         public guid id { get; set; }         public datetime timestamp { get; set; }         public string address { get; set; }         public string name { get; set; }         public string city { get; set; }         public string state { get; set; }      } 

and following context:

public class applicationdbcontext : dbcontext<mymodel>     {         public applicationdbcontext()             : base("defaultconnection")         {         }          public virtual dbset<mymodel> mymodels { get; set; }          protected override void onmodelcreating(dbmodelbuilder modelbuilder)         {             base.onmodelcreating(modelbuilder);             modelbuilder.entity<mymodel>().totable("mymodels");         }     } 

when saving in db, assign fields timestamp, address, name , rest of fields update them later (city, state):

var model = new mymodel(){timestamp = datetime.now, address = "value here", name = "value here"}; _dbcontext.mymodels.add(model); _dbcontext.savechanges(); => persisted fine in db 

.... later on ...

var model = _dbcontext.mymodels.where(...); model.state = "value here"; //and rest of properties updated here _dbcontext.savechanges(); => updated fine in db  

.... , later

var model = _dbcontext.mymodels.where(...); 

=> here properties initialized first retrieved correctly (timestamp, address, name) while updated properties (city, state) null though in db have correct values.

what doing wrong?

edit:

if reinitialize _dbcontext

_dbcontext = new applicationcontext() var model = _dbcontext.mymodels.where(...);  

in last code snippet before querying collection, correct results. why happen?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -