public string Name { get;set; }
public class CampaignProxy
public string Name { get;set; }
public static object SetEntityFieldsFixed(object entity, object from, params string[] properties)
var entityType = entity.GetType();
var fromType = from.GetType();
foreach (string field in properties)
var entityProp = entityType.GetProperty(field);
var fromProp = fromType.GetProperty(field);
throw new ArgumentException(field + " field is not found on entity", "field");
entityProp.SetValue(entity, fromProp.GetValue(from, null), null);
public static object SetEntityFieldsBug(object entity, object from, params string[] properties)
var type = entity.GetType();
foreach (string field in properties)
if (type.GetProperty(field) == null)
throw new ArgumentException(field + " field is not found on entity", "field");
var pInfo = type.GetProperty(field);
var prop = type.GetProperty(field);
prop.SetValue(entity, prop.GetValue(from, null), null);
public static void Main()
var dbModel = new CampaignProxy { Name = "Hakan" };
var toBeUpdateModel = new Campaign { Name = "Cafer" };
SetEntityFieldsBug(dbModel, toBeUpdateModel, "Name");
Console.WriteLine(dbModel.Name);