I am updating data EF table item by hashtable dynamically but when I do the save changes, my data is not updating in the DB table.
UserMaster EntityObj = context.UserMasters.FirstOrDefault(user => user.DataID == DataID);
Type description = typeof(UserMaster);
foreach (string htKey in ht.Keys)
{
PropertyInfo property = description.GetProperty(htKey);
object htValue = ht[htKey];
object result = AppHelper.ConvertValueType(htValue, property.PropertyType.Name);
property.SetValue(EntityObj, result);
}
context.SaveChanges();
Here ht is hastable. What is wrong with this code or is there anyway to dynamically bind data to the db model object and update data in database?
Hashtable ht = new Hashtable();
ht.Add( "username", "Abhi" );
ht.Add( "Role", "Admin" );
ht.Add( "FirstName", "Abhi" );
ht.Add( "email", "ab@cd.com" );