Esempio n. 1
0
        /// <summary>
        /// 保存一个对象到数据库中,保存前,根据对象的Maping信息,生成对应的insert sql.
        /// </summary>
        /// <param name="tableObject">含Mapping信息的对象. 自增长列需要加 IsDbGenerated = true, 只支持SqlServer</param>
        /// <returns>自增长列的值,没有自增长列时返回0</returns>
        public int Insert(Object tableObject)
        {
            Object2Insert obj2Insert = getObject2Insert();

            obj2Insert.parse(tableObject);

            int result = 0;

            // SqlServer中包括Identity列时,需要返回Identity的值
            if (obj2Insert.IsSqlServerIdentityTable)
            {
                var table = this.Query(obj2Insert.AsSql4ServerIdentityTable(), obj2Insert.GetSqlParameterNames(), obj2Insert.GetSqlParameterValues());
                result = (int)table.Rows[0][0];
                var id = table.Rows[0][1];
                obj2Insert.OutputValues.Add(id);
            }
            else
            {
                result = this.Execute(obj2Insert.AsSql(), obj2Insert.GetSqlParameterNames(), obj2Insert.GetSqlParameterValues());
            }

            obj2Insert.SetOutputValues(tableObject);

            return(result);
        }
Esempio n. 2
0
 private Object2Insert getObject2Insert()
 {
     if (this.obj2Insert == null)
     {
         this.obj2Insert             = new Object2Insert();
         this.obj2Insert.adoTemplate = this;
     }
     return(this.obj2Insert);
 }