示例#1
0
        public IMultipleResultReader GetMultiple(IDbConnection connection, IGetMultiplePredicate predicate, IDbTransaction transaction, int?commandTimeout)
        {
            if (SqlGenerator.SupportsMultipleStatements())
            {
                return(GetMultipleByBatch(connection, predicate, transaction, commandTimeout));
            }

            return(GetMultipleBySequence(connection, predicate, transaction, commandTimeout));
        }
示例#2
0
        protected SequenceReaderResultReader GetMultipleBySequence(IDbConnection connection, IGetMultiplePredicate predicate, IDbTransaction transaction, int?commandTimeout)
        {
            IList <SqlMapper.GridReader> items = new List <SqlMapper.GridReader>();

            foreach (var item in predicate.Items)
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                IClassMapper classMap      = SqlGenerator.Configuration.GetMap(item.Type);
                IPredicate   itemPredicate = item.Value as IPredicate;
                if (itemPredicate == null && item.Value != null)
                {
                    itemPredicate = GetPredicate(classMap, item.Value);
                }

                string            sql = SqlGenerator.Select(classMap, itemPredicate, item.Sort, parameters);
                DynamicParameters dynamicParameters = new DynamicParameters();
                foreach (var parameter in parameters)
                {
                    dynamicParameters.Add(parameter.Key, parameter.Value);
                }

                SqlMapper.GridReader queryResult = connection.QueryMultiple(sql, dynamicParameters, transaction, commandTimeout, CommandType.Text);
                items.Add(queryResult);
            }

            return(new SequenceReaderResultReader(items));
        }
示例#3
0
        protected GridReaderResultReader GetMultipleByBatch(IDbConnection connection, IGetMultiplePredicate predicate, IDbTransaction transaction, int?commandTimeout)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();
            StringBuilder sql = new StringBuilder();

            foreach (var item in predicate.Items)
            {
                IClassMapper classMap      = SqlGenerator.Configuration.GetMap(item.Type);
                IPredicate   itemPredicate = item.Value as IPredicate;
                if (itemPredicate == null && item.Value != null)
                {
                    itemPredicate = GetPredicate(classMap, item.Value);
                }

                sql.AppendLine(SqlGenerator.Select(classMap, itemPredicate, item.Sort, parameters) + SqlGenerator.Configuration.Dialect.BatchSeperator);
            }

            DynamicParameters dynamicParameters = new DynamicParameters();

            foreach (var parameter in parameters)
            {
                dynamicParameters.Add(parameter.Key, parameter.Value);
            }

            SqlMapper.GridReader grid = connection.QueryMultiple(sql.ToString(), dynamicParameters, transaction, commandTimeout, CommandType.Text);
            return(new GridReaderResultReader(grid));
        }