This possibly could be un-related to databinding or entity framework. But this is the scenario my problem is occurring in.
This is my code, saving a new entity and then re-binding:
Run run = new Run();
run.Distance = 111;
rc.RunSet.AddObject(run);
rc.SaveChanges();
GridViewRuns.DataSource = rc.RunSet.ToList();
GridViewRuns.DataBind();
I am getting this exception, on the Databind()
call.
Property accessor 'Distance' on object 'runwebforms.Data.Run' threw the following exception:'Object does not match target type.'
I dont understand, as this code works fine:
RunsContainer rc = new RunsContainer();
GridViewRuns.DataSource = rc.RunSet.ToList();
GridViewRuns.DataBind();
Its seems to be due to the fact I am binding a new entity. Is this something to do with the proxy objects?