Пример #1
0
        /// <summary>
        /// 删除obj对象
        /// </summary>
        public static bool Delete(OracleConnection connection, object obj)
        {
            Type          type   = obj.GetType();
            StringBuilder strSql = new StringBuilder();

            try
            {
                strSql.Append(string.Format("delete from {0}", DBAttribute.getDBTable(type)));
            }
            catch (ArgumentException e)
            {
                throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n");
            }
            List <string> propertyPrimaryKeyList   = new List <string>();
            List <string> propertyPrimaryValueList = new List <string>();

            DBAttribute.getDBPrimaryElement(type, obj, propertyPrimaryKeyList, propertyPrimaryValueList);
            if (!(propertyPrimaryKeyList.Any() && propertyPrimaryValueList.Any()))
            {
                throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n");
            }
            strSql.Append(string.Format(" where "));
            for (int i = 0; i < propertyPrimaryKeyList.Count; ++i)
            {
                strSql.Append(string.Format(" {0}={1} AND", propertyPrimaryKeyList[i], propertyPrimaryValueList[i]));
            }
            strSql.Length -= 3;
            return(ExecuteSql(connection, strSql.ToString()) > 0);
        }
Пример #2
0
        public static bool existObj(object obj)
        {
            List <string> prikey = new List <string>(), prival = new List <string>();

            DBAttribute.getDBPrimaryElement(obj.GetType(), obj, prikey, prival);
            return(exist(obj.GetType(), prikey, prival));
        }
Пример #3
0
        public static T getObject <T>(T Obj)
        {
            OracleConnection conn = pool.fetchConnection();
            StringBuilder    sb   = new StringBuilder();

            sb.Append(string.Format("select * from {0} where ", DBAttribute.getDBTable(typeof(T))));
            List <string> key = new List <string>(), val = new List <string>();

            DBAttribute.getDBPrimaryElement(typeof(T), Obj, key, val);
            int len = key.Count();

            for (int i = 0; i < len; ++i)
            {
                sb.Append(string.Format(" {0}={1} AND ", key[i], val[i]));
            }
            sb.Length -= 4;
            List <T> lt  = testQuery <T>(sb.ToString());
            T        res = lt.Count() == 0?Obj:lt[0];

            pool.releaseConnection(conn);
            return(res);
        }