示例#1
0
        public async Task <IEnumerable <Table> > QueryTable()
        {
            _logger.LogInformation($"----Db:{DbName} Provider:{DbProviderName}, QueryTable Start! ----");
            IEnumerable <Table> tables;

            try
            {
                SqlMapper.BeginSession();
                tables = await SqlMapper.QueryAsync <Table>(new RequestContext
                {
                    Scope   = Scope,
                    SqlId   = "QueryTable",
                    Request = new { DBName = DbName }
                });

                foreach (var table in tables)
                {
                    table.Columns = await SqlMapper.QueryAsync <Column>(new RequestContext
                    {
                        Scope   = Scope,
                        SqlId   = "QueryColumn",
                        Request = new { DBName = DbName, TableId = table.Id, TableName = table.Name }
                    });
                }
            }
            finally
            {
                SqlMapper.EndSession();
            }
            _logger.LogInformation($"----Db:{DbName} Provider:{DbProviderName},Tables:{tables.Count()} QueryTable End! ----");
            return(tables);
        }
        public void Query_Scoped()
        {
            int i = 0;

            SqlMapper.BeginSession();
            for (i = 0; i < testTime; i++)
            {
                var list = SqlMapper.Query <T_Test>(new RequestContext
                {
                    Scope = "T_Test",
                    SqlId = "GetList",
                });
            }
            SqlMapper.EndSession();
            Assert.Equal <int>(i, testTime);
        }