Beispiel #1
0
        /// <summary>
        /// 使用附带新值的实体信息更新指定实体属性的值(把原来的记录都删除,再添加一条)
        /// </summary>
        /// <param name="propertyExpression">属性表达式</param>
        /// <param name="isSave">是否执行保存</param>
        /// <param name="entity">附带新值的实体信息,必须包含主键</param>
        /// <returns>操作影响的行数</returns>

        /*public int Update(Expression<Func<TEntity, object>> propertyExpression, TEntity entity, bool isSave = true)
         * {
         *  //throw new NotSupportedException("上下文公用,不支持按需更新功能。");
         *  PublicHelper.CheckArgument(propertyExpression, "propertyExpression");
         *  PublicHelper.CheckArgument(entity, "entity");
         *  EFContext.RegisterModified<TEntity>(propertyExpression, entity);
         *  if (isSave)
         *  {
         *      var dbSet = EFContext.Set<TEntity>();
         *      dbSet.Local.Clear();
         *      var entry = EFContext.DbContext.Entry(entity);
         *      return EFContext.Commit(false);
         *  }
         *  return 0;
         * }*/

        public int Update(Expression <Func <TEntity, object> > propertyExpression, params TEntity[] entities)
        {
            PublicHelper.CheckArgument(propertyExpression, "propertyExpression");
            PublicHelper.CheckArgument(entities, "entity");
            DbContextExtensions.Update <TEntity>(this.EFContext.DbContext, propertyExpression, entities);
            return(DbContextExtensions.SaveChanges(this.EFContext.DbContext, false));
            //EFContext.Update<TEntity>(propertyExpression, entities);
            //return EFContext.Commit(false);
        }
 public void Update <TEntity>(Expression <Func <TEntity, object> > propertyExpression, params TEntity[] entities)
     where TEntity : class
 {
     DbContextExtensions.Update <TEntity>(Context, propertyExpression, entities);
     IsCommitted = false;
 }