示例#1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="UseIndexClause" /> class.
        /// </summary>
        /// <param name="indexName">Name of the index to use.</param>
        /// <param name="indexType">Type of the index to use.</param>
        public UseIndexClause(string indexName, N1QlIndexType indexType)
        {
            if (string.IsNullOrEmpty(indexName))
            {
                throw new ArgumentNullException(nameof(indexName));
            }

            IndexName = indexName;
            IndexType = indexType;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="UseIndexClause" /> class.
        /// </summary>
        /// <param name="indexName">Name of the index to use.</param>
        /// <param name="indexType">Type of the index to use.</param>
        public UseIndexClause(string indexName, N1QlIndexType indexType)
        {
            if (string.IsNullOrEmpty(indexName))
            {
                throw new ArgumentNullException("indexName");
            }

            IndexName = indexName;
            IndexType = indexType;
        }
示例#3
0
        /// <summary>
        /// Provides an index hint to the query engine.
        /// </summary>
        /// <typeparam name="T">Type of items being queried.</typeparam>
        /// <param name="source">Items being queried.</param>
        /// <param name="indexName">Name of the index to use.</param>
        /// <param name="indexType">Type of the index to use.</param>
        /// <returns>Modified IQueryable</returns>
        public static IQueryable <T> UseIndex <T>(this IQueryable <T> source, string indexName, N1QlIndexType indexType)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (!Enum.IsDefined(typeof(N1QlIndexType), indexType))
            {
                throw new ArgumentOutOfRangeException("indexType");
            }

            return(source.Provider.CreateQuery <T>(
                       Expression.Call(
                           UseIndexMethod
                           .MakeGenericMethod(typeof(T)),
                           source.Expression,
                           Expression.Constant(indexName),
                           Expression.Constant(indexType))));
        }
        /// <summary>
        /// Provides an index hint to the query engine.
        /// </summary>
        /// <typeparam name="T">Type of items being queried.</typeparam>
        /// <param name="source">Items being queried.</param>
        /// <param name="indexName">Name of the index to use.</param>
        /// <param name="indexType">Type of the index to use.</param>
        /// <returns>Modified IQueryable</returns>
        public static IQueryable <T> UseIndex <T>(this IQueryable <T> source, string indexName, N1QlIndexType indexType)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (indexType < N1QlIndexType.Gsi || indexType > N1QlIndexType.View)
            {
                throw new ArgumentOutOfRangeException(nameof(indexType));
            }

            return(source.Provider.CreateQuery <T>(
                       Expression.Call(
                           QueryExtensionMethods.UseIndexWithType.MakeGenericMethod(typeof(T)),
                           source.Expression,
                           Expression.Constant(indexName),
                           Expression.Constant(indexType))));
        }