Example #1
0
        /// <summary>
        /// 直接运行SQL语句
        /// </summary>
        /// <param name="ConnectionName">连接名</param>
        /// <param name="sql">sql语句</param>
        /// <param name="opType">操作类型</param>
        /// <returns></returns>
        public static object RunSQL(string connectionName, string sql, emOperationType opType)
        {
            string wrongMessage = "";
            object obj          = null;

            DBLInit _DBLInit = new DBLInit(connectionName);

            switch (opType)
            {
            case emOperationType.select:
                obj = _DBLInit.GetDataTable(sql, out wrongMessage);
                break;

            case emOperationType.delete:
            case emOperationType.insert:
            case emOperationType.update:
                obj = _DBLInit.ProcessSql(sql, opType, out wrongMessage);
                break;
            }

            MyORM.Log.WriteInfo(connectionName + "-" + opType.ToString() + "-" + sql);

            if (!string.IsNullOrEmpty(wrongMessage))
            {
                MyORM.Log.WriteError(wrongMessage);
            }

            return(obj);
        }
Example #2
0
        private string _PrimaryKey = "tid"; //主键 固定为tid

        /// <summary>
        /// 初始化表名及连接字符串
        /// </summary>
        public OrmOperation()
        {
            try
            {
                Type          myType    = typeof(T);
                string        className = myType.Name;
                InitAttribute iAttr     = myType.GetCustomAttributes(true)[0] as InitAttribute;

                //数据表名
                _TableName = iAttr._TableName;

                //数据库连接名
                _DBLInit = new DBLInit(iAttr._ConnectionName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        private string _PrimaryKey; //主键名

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="DBLInit">数据源</param>
        /// <param name="TableName">表名</param>
        /// <param name="PrimaryKey">主键名</param>
        public OrmOperationBase(DBLInit DBLInit, string TableName, string PrimaryKey)
        {
            _DBLInit    = DBLInit;
            _TableName  = TableName;
            _PrimaryKey = PrimaryKey;
        }