コード例 #1
0
        protected SequenceReaderResultReader GetMultipleBySequence(IDbConnection connection, GetMultiplePredicate 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));
        }
コード例 #2
0
        protected GridReaderResultReader GetMultipleByBatch(IDbConnection connection, GetMultiplePredicate 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));
        }