Ejemplo n.º 1
0
        /// <summary>更新</summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public virtual Int32 Update(IEntity entity)
        {
            var ds = entity.Dirtys;

            // 没有脏数据,不需要更新
            if (ds.Count == 0)
            {
                return(0);
            }

            DbParameter[] dps = null;
            var           sql = SQL(entity, DataObjectMethodType.Update, ref dps);

            if (String.IsNullOrEmpty(sql))
            {
                return(0);
            }

            var op      = EntityFactory.CreateOperate(entity.GetType());
            var session = op.Session;
            //Int32 rs = dps != null && dps.Length > 0 ? session.Execute(sql, CommandType.Text, dps) : session.Execute(sql);
            Int32 rs = dps != null && dps.Length > 0 ? session.Execute(false, true, sql, CommandType.Text, dps) : session.Execute(false, true, sql);

            //清除脏数据,避免重复提交
            ds.Clear();

            //entity.ClearAdditionalValues();
            EntityAddition.ClearValues(entity as EntityBase);

            return(rs);
        }
Ejemplo n.º 2
0
        /// <summary>更新</summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public virtual Int32 Update(IEntity entity)
        {
            var ds = entity.Dirtys;
            // 没有脏数据,不需要更新
            if (ds.Count == 0) return 0;

            IDataParameter[] dps = null;
            var sql = SQL(entity, DataObjectMethodType.Update, ref dps);
            if (String.IsNullOrEmpty(sql)) return 0;

            var op = EntityFactory.CreateOperate(entity.GetType());
            var session = op.Session;
            var rs = session.Execute(sql, CommandType.Text, dps);

            //清除脏数据,避免重复提交
            ds.Clear();

            EntityAddition.ClearValues(entity as EntityBase);

            return rs;
        }