Beispiel #1
0
        /// <summary>
        /// 部分更新实体
        /// </summary>
        /// <param name="id">标识</param>
        /// <param name="entity">部分实体,建议采用new { 参数1=值1 ..} 动态对象构造</param>
        /// <param name="autoCommit">是否自动执行提交</param>
        /// <param name="tranActions">事务执行委托方法</param>
        public virtual void Update <T>(string id, object entity, bool autoCommit = true, Func <IRepository, bool> tranActions = null) where T : AggregateRoot, new()
        {
            T t = this.Single <T>(id);

            if (t != null)
            {
                T t2 = entity.Adapter(t, new string[0]);
                if (this.OnBeforeChanged != null)
                {
                    this.OnBeforeChanged(2, this._dbContext, t2);
                }
                this._dbContext.Update <T>(t2);
                if (tranActions != null)
                {
                    tranActions(this._dbContext);
                }
                if (this.OnAfterChanged != null)
                {
                    this.OnAfterChanged(2, this._dbContext, t2);
                }
                if (autoCommit)
                {
                    this.Commit();
                }
            }
        }