public static TEntity PatchEntity <TEntity>(this BaseDto model, TEntity dbEntity, IMapper mapper) { var dbModel = model.ToEntity <TEntity>(mapper); var notNullProeprties = dbModel .GetType() .GetProperties() .Where(x => !CheckNullOrEmpty(x.GetValue(dbModel, null))).ToList(); foreach (var property in notNullProeprties) { var dbProperty = dbEntity.GetType().GetProperty(property.Name); if (dbProperty != null) { if (property.GetValue(dbModel, null) != dbProperty.GetValue(dbEntity, null)) { if (dbProperty != null) { property.SetValue(dbEntity, dbProperty.GetValue(dbModel, null)); } } } } return(dbEntity); }