Esempio n. 1
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public DbArray Query(string sql, params object[] args)
        {
            var list = new DbArray();

            this.Open();
            using (DbCommand cmd = _conn.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.Transaction = _tran;
                AddDbParameter(cmd, args);

                using (DbDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        DbObject obj = new DbObject();
                        for (var i = 0; i < dr.FieldCount; i++)
                        {
                            obj.Add(dr.GetName(i), dr.GetValue(i));
                        }

                        list.Add(obj);
                    }
                    dr.Close();
                }
            }

            return(list);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public DbArray GetArray(string name)
        {
            if (this[name] is DbArray)
            {
                return((DbArray)this[name]);
            }

            var jArr = this[name] as Newtonsoft.Json.Linq.JArray;

            if (jArr == null)
            {
                return(null);
            }

            DbArray arr = new DbArray();

            foreach (Newtonsoft.Json.Linq.JObject obj in jArr)
            {
                arr.Add((DbObject)obj.ToObject(typeof(DbObject)));
            }

            return(arr);
        }