Пример #1
0
        /// <summary>
        /// 添加新模型
        /// </summary>
        public virtual KeyValuePair <bool, string> AddNew()
        {
            Dictionary <string, object> paramList = new Dictionary <string, object>();
            //return new KeyValuePair<bool, string>(false, this.SQLInsert(paramList));
            bool   b_exec;
            string sql = this.SQLInsert(paramList);

            #region 自增属性赋值处理
            Type ttp = this.GetType();
            if (GLB_CACHE_MODELPROPERTYS.ContainsKey(ttp))
            {
                var idfprop = GLB_CACHE_MODELPROPERTYS[ttp].IdentityProperty;
                if (idfprop != null)
                {
                    sql += " SELECT SCOPE_IDENTITY() c";
                    int idfval = Dbop.GetSingleInt(sql, paramList);
                    if (idfval > 0)
                    {
                        PropertySetValue(this, idfprop, idfval);
                        b_exec = true;
                    }
                    else
                    {
                        b_exec = false;
                    }
                    return(new KeyValuePair <bool, string>(b_exec, null));
                }
            }
            #endregion

            b_exec = Dbop.ExecuteSqlSuc(sql, paramList);
            return(new KeyValuePair <bool, string>(b_exec, null));
        }