Exemplo n.º 1
0
        /// <summary>
        /// get insert sql
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="parameters"></param>
        public override String GetInsert(DbEntity entity, out IDbDataParameter[] parameters)
        {
            parameters = null;
            var parameterList = new List <IDbDataParameter>(entity.GetInitializePropertyCount());

            var filed  = new StringBuilder();
            var values = new StringBuilder();

            //object property
            Dictionary <string, object> .Enumerator etor = entity.GetEnumerator();

            //Type type;
            while (etor.MoveNext())
            {
                filed.Append("," + etor.Current.Key);
                if (etor.Current.Value != null && etor.Current.Value is DateTime)
                {
                    values.AppendFormat(",#{0}#", etor.Current.Value);
                }
                else
                {
                    values.AppendFormat(",{0}{1}", Factory.ParameterChar, etor.Current.Key);
                    parameterList.Add(Factory.CreateParameter(etor.Current.Key, etor.Current.Value));
                }
            }

            //remove comma
            if (filed.Length > 0)
            {
                filed  = filed.Remove(0, 1);
                values = values.Remove(0, 1);
            }
            else
            {
                return(null);
            }

            return(string.Format("INSERT INTO {0} ({1}) VALUES ({2})", entity.GetTableName(), filed.ToString(), values.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// get update sql
        /// </summary>
        /// <param name="where">更新条件</param>
        /// <param name="update"></param>
        /// <param name="parameters"></param>
        public override String GetUpdate(DbEntity update, DbEntity where, out IDbDataParameter[] parameters)
        {
            parameters = null;
            var parameterList = new List <IDbDataParameter>(update.GetInitializePropertyCount() + where.GetInitializePropertyCount());

            StringBuilder build = new StringBuilder();

            //object property
            Dictionary <string, object> .Enumerator etor = update.GetEnumerator();
            //Type type;
            while (etor.MoveNext())
            {
                if (etor.Current.Value != null && etor.Current.Value is DateTime)
                {
                    build.AppendFormat(",{0}=#{1}#", etor.Current.Key, etor.Current.Value);
                }
                else
                {
                    build.AppendFormat(",{0}={1}{0}", etor.Current.Key, Factory.ParameterChar);
                    parameterList.Add(Factory.CreateParameter(etor.Current.Key, etor.Current.Value));
                }
            }

            string result = null;

            if (build.Length > 0)
            {
                IDbDataParameter[] whereParameters = null;
                result = string.Format("UPDATE {0} SET {1}{2}", update.GetTableName(), build.Remove(0, 1).ToString(), this.GetWhere(where, out whereParameters));
                if (whereParameters != null)
                {
                    parameterList.AddRange(whereParameters);
                }
            }
            parameters = parameterList.ToArray();
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 返回一个数据对象
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="entity">查询对象</param>
 public T GetRow <T>(DbEntity entity) where T : IDbEntity
 {
     IDbDataParameter[] parameters = null;
     return(this.GetRow <T>(this.SqlBuilder.GetSelect(entity, "*", out parameters), false, parameters));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 返回一个数据对象
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="entity">查询对象</param>
 /// <param name="storedProcedure">要执行的存储过程名</param>
 public T GetRow <T>(DbEntity entity, string storedProcedure) where T : IDbEntity
 {
     return(this.GetRow <T>(storedProcedure, true, this.CreateParameter(entity)));
 }
Exemplo n.º 5
0
 /// <summary>
 /// 获取指定对象的记录数
 /// </summary>
 /// <param name="entity">对象</param>
 /// <param name="storedProcedure">要执行的存储过程名</param>
 public virtual int GetCount(DbEntity entity, string storedProcedure)
 {
     return(Convert.ToInt32(this.GetScalar(storedProcedure, true, this.CreateParameter(entity))));
 }
Exemplo n.º 6
0
 /// <summary>
 /// 获取指定对象的记录数
 /// </summary>
 /// <param name="entity">对象</param>
 public virtual int GetCount(DbEntity entity)
 {
     IDbDataParameter[] parameters = null;
     entity.SetQuerySize(1);
     return(Convert.ToInt32(GetScalar(this.SqlBuilder.GetSelect(entity, "COUNT(*)", out parameters), false, parameters)));
 }
Exemplo n.º 7
0
 /// <summary>
 /// 获取第一行第一列的数据
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="entity">对象</param>
 /// <param name="storedProcedure">要执行的存储过程名</param>
 public virtual T GetScalar <T>(DbEntity entity, string storedProcedure)
 {
     return((T)this.GetScalar(storedProcedure, true, this.CreateParameter(entity)));
 }
Exemplo n.º 8
0
 /// <summary>
 /// 获取第一行第一列的数据
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="entity">对象</param>
 public virtual T GetScalar <T>(DbEntity entity)
 {
     return((T)this.GetScalar(entity));
 }
Exemplo n.º 9
0
 /// <summary>
 /// 获取第一行第一列的数据
 /// </summary>
 /// <param name="entity">对象</param>
 public virtual Object GetScalar(DbEntity entity)
 {
     IDbDataParameter[] parameters = null;
     return(GetScalar(this.SqlBuilder.GetSelect(entity, "*", out parameters), false, parameters));
 }
Exemplo n.º 10
0
 /// <summary>
 /// 返回一个数据表
 /// </summary>
 /// <param name="entity">数据对象</param>
 /// <param name="storedProcedure">要执行的存储过程名</param>
 public virtual DataTable GetDataTable(DbEntity entity, string storedProcedure)
 {
     return(this.GetDataTable(storedProcedure, true, this.CreateParameter(entity)));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 返回一个数据表
 /// </summary>
 /// <param name="entity">数据对象</param>
 public virtual DataTable GetDataTable(DbEntity entity)
 {
     IDbDataParameter[] parameters = null;
     return(GetDataTable(this.SqlBuilder.GetSelect(entity, "*", out parameters), false, parameters));
 }
Exemplo n.º 12
0
 /// <summary>
 /// 执行数据对象修改
 /// </summary>
 /// <param name="update">数据对象</param>
 /// <param name="where">条件对像</param>
 public virtual int Update(DbEntity update, DbEntity where)
 {
     IDbDataParameter[] parameters = null;
     return(Execute(this.SqlBuilder.GetUpdate(update, where, out parameters), false, parameters));
 }
Exemplo n.º 13
0
 /// <summary>
 /// 执行数据对象插入请求
 /// </summary>
 /// <param name="entity">数据对象</param>
 public virtual int Insert(DbEntity entity)
 {
     IDbDataParameter[] parameters = null;
     return(Execute(this.SqlBuilder.GetInsert(entity, out parameters), false, parameters));
 }
Exemplo n.º 14
0
 /// <summary>
 /// 执行一个语句或过程
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="storedProcedure">存储过程名</param>
 /// <returns>受影响行数</returns>
 public virtual int Execute(DbEntity entity, string storedProcedure)
 {
     return(this.Execute(storedProcedure, true, this.CreateParameter(entity)));
 }
Exemplo n.º 15
0
 /// <summary>
 /// get delete sql
 /// </summary>
 /// <param name="where">实体</param>
 /// <param name="parameters"></param>
 public virtual String GetDelete(DbEntity where, out IDbDataParameter[] parameters)
 {
     return(string.Format("DELETE FROM {0}{1}", where.GetTableName(), this.GetWhere(where, out parameters)));
 }