Unfortunately, the DbContext.Entry
method that allows you to attach the object to back to the DbContext, was added in EF5+.
As @Nilesh mentioned, for easy model binding without copying each property you should use a tool like AutoMapper or ValueInjecter.
With AutoMapper for example, you will simply do that:
private void btnUpdate_Click(object sender, EventArgs e)
{
TModel t = new TModel();
t.ID = 1;
t.Name = "a";
TestDBEntities en = new TestDBEntities();
var entity = en.T.First(m => m.ID == 1);
Mapper.Map<TModel, T>(t, entity);
en.SaveChanges();
MessageBox.Show("Update");
}
In case a more complex mapping is required, you can configure the mapping with Mapper.CreateMap
method. Check the documentation for more examples.