public static TEntity Sync2Entity <TViewModel, TEntity>(this TViewModel viewModel, string viewModelPrefix, IRepository <TEntity> repository, params string[] ignoreNames) where TViewModel : class where TEntity : class { var expression = repository.GetEqualKeyFunc(ViewModelHelper.GetKeyValue <TViewModel>(viewModel)); var target = repository.Get(expression); var properties = typeof(TViewModel).GetProperties(); var ignoreNameList = new List <string>(ignoreNames); foreach (var propertyInfo in properties) { var attribute = Attribute.GetCustomAttribute(propertyInfo, typeof(EditableAttribute)) ?? Attribute.GetCustomAttribute(propertyInfo, typeof(ScaffoldColumnAttribute)); if (attribute != null) { ignoreNameList.Add(propertyInfo.Name); } } viewModel.Inject(viewModelPrefix, "", target, ignoreNameList.ToArray()); return(target); }