Ejemplo n.º 1
0
        private List <E> LoadFromReader <E>(TableAliasNameManager aliasManager, IDataReader reader)
            where E : EntityBase
        {
            List <E> lst = new List <E>();

            if (reader != null && !reader.IsClosed)
            {
                aliasManager.InitMapping(reader);
                while (reader.Read())
                {
                    object value = aliasManager.LoadFromReader(reader);
                    if (value != null)
                    {
                        E obj = value as E;
                        //obj.SetBaseList(lst);
                        lst.Add(obj);
                    }
                }
            }
            return(lst);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取第一条记录
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="BQL"></param>
        /// <returns></returns>
        public E GetUnique <E>(BQLQuery BQL, bool useCache)
            where E : EntityBase, new()
        {
            Type tableType = typeof(E);
            TableAliasNameManager aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(tableType)));


            AbsCondition con = BQLKeyWordManager.ToCondition(BQL, _oper.DBInfo, aliasManager, true);
            Dictionary <string, bool> cacheTables = null;

            if (useCache)
            {
                cacheTables = con.CacheTables;
            }
            string      sql    = con.DBinfo.CurrentDbAdapter.GetTopSelectSql(con as SelectCondition, 1);
            E           ret    = default(E);
            IDataReader reader = _oper.Query(sql, con.DbParamList, cacheTables);

            try
            {
                con.Oper = _oper;
                bool hasValue = true;
                aliasManager.InitMapping(reader);
                if (reader.Read())
                {
                    ret = aliasManager.LoadFromReader(reader) as E;
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(ret);
        }