1.更新单个字段

/// <summary>
        /// 更新字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="conditions">where 筛选对象</param>
        /// <param name="updateLamda">更新字段</param>
        /// <returns></returns>
        public IEnumerable<T> Update<T>( Expression<Func<T, bool>> conditions,Func<T, dynamic> updateLamda) where T : ModelBase
        {            
            List<T> setList;
            if (conditions!=null)
            {
                setList= this.Set<T>().Where(conditions).ToList();
            }
            else
            {
                setList = this.Set<T>().ToList();
            }
            foreach (var item in setList)
            {
                SetValue<T>(item, updateLamda);
                this.Entry<T>(item).State = EntityState.Modified;
            }
            this.SaveChanges();
            return setList;
        }

        public dynamic SetValue<T>(T entity, Func<T, dynamic> expr)
        {
            return expr(entity);
        }
更新单个字段

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2021-12-19
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2021-06-27
  • 2021-07-18
  • 2022-12-23
相关资源
相似解决方案