Ejemplo n.º 1
0
        public static ReposityMeta GetMeta(int mid)
        {
            ReposityMeta rm = CacheService.Get("MID_" + mid) as ReposityMeta;

            if (rm == null)
            {
                string sql = "SELECT * FROM meta_reposity WHERE id=@id;" +
                             "SELECT * FROM meta_reposity_map WHERE rid=@id ORDER BY id";

                using (IDataReader dr = DBH.ExecuteReader(QA.DBCS_MAIN, CommandType.Text, sql, new SqlParameter("@id", mid)))
                {
                    if (dr != null)
                    {
                        if (dr.Read())
                        {
                            rm        = new ReposityMeta();
                            rm.Id     = dr.GetInt32(dr.GetOrdinal("id"));
                            rm.OP     = dr.GetByte(dr.GetOrdinal("op"));
                            rm.Total  = dr.GetInt32(dr.GetOrdinal("total"));
                            rm.Name   = dr.GetString(dr.GetOrdinal("name"));
                            rm.Table1 = dr.GetString(dr.GetOrdinal("table1"));
                            rm.Table2 = (dr["table2"] is DBNull) ? null : dr.GetString(dr.GetOrdinal("table2"));
                            rm.Table3 = (dr["table3"] is DBNull) ? null : dr.GetString(dr.GetOrdinal("table3"));

                            if (dr.NextResult())
                            {
                                rm.Maps = new List <ReposityMap>();
                                while (dr.Read())
                                {
                                    ReposityMap map = new ReposityMap();
                                    map.Id         = dr.GetInt32(dr.GetOrdinal("id"));
                                    map.RId        = dr.GetInt32(dr.GetOrdinal("rid"));
                                    map.Name       = dr.GetString(dr.GetOrdinal("name"));
                                    map.Field      = dr.GetString(dr.GetOrdinal("field"));
                                    map.TableIndex = dr.GetInt32(dr.GetOrdinal("tableindex"));
                                    map.PK         = dr.GetBoolean(dr.GetOrdinal("pk"));
                                    map.AutoId     = dr.GetBoolean(dr.GetOrdinal("autoid"));
                                    rm.Maps.Add(map);
                                }
                            }
                        }
                    }
                }//using
            }

            return(rm);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  根据查询条件获取指定类型的对象,需要传递Entity Build Callback
        /// </summary>
        /// <param name="connectionString">连接串</param>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <param name="callback">Entity Build方法</param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public static T Get(string connectionString, CommandType commandType, string commandText, ToEntityCallback callback, params SqlParameter[] commandParameters)
        {
            T t = null;

            using (IDataReader dr = DBH.ExecuteReader(connectionString, commandType, commandText, commandParameters))
            {
                if (dr != null)
                {
                    if (dr.Read())
                    {
                        t = callback(dr);
                    }

                    dr.Close();
                }
            }

            return(t);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  根据查询条件自动生成对应的对象,不需要传递Entity Build Callback,但需要实体对象定义对应的属性。
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public static T Get(string commandText, params SqlParameter[] commandParameters)
        {
            T t = null;

            using (IDataReader dr = DBH.ExecuteReader(QA.DBCS_MAIN, CommandType.Text, commandText, commandParameters))
            {
                if (dr != null)
                {
                    if (dr.Read())
                    {
                        t = Build(dr);
                    }

                    dr.Close();
                }
            }

            return(t);
        }
Ejemplo n.º 4
0
        public static IList <T> List(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            IList <T> tList = null;

            using (IDataReader dr = DBH.ExecuteReader(connectionString, commandType, commandText, commandParameters))
            {
                if (dr != null)
                {
                    try
                    {
                        tList = new List <T>();
                        while (dr.Read())
                        {
                            tList.Add(Build(dr));
                        }
                    }
                    catch { }
                    finally { dr.Close(); }
                }
            }

            return(tList);
        }