当前位置: 首页>>代码示例>>C#>>正文


C# Query.Add方法代码示例

本文整理汇总了C#中Query.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Query.Add方法的具体用法?C# Query.Add怎么用?C# Query.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Query的用法示例。


在下文中一共展示了Query.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			var counter = 0;

			// check for id, guid or pointer
			int id;
			if (parameters.TryGetAndRemove(context, "id", out id))
			{
				query.Add(new IsPropertyEqualSpecification("id", id));
				counter++;
			}
			string guids;
			if (parameters.TryGetAndRemove(context, "guid", out guids) && !string.IsNullOrEmpty(guids))
			{
				// split the value
				var values = guids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
				query.Add(new IsPropertyInSpecification("guid", values));
				counter++;
			}
			NodePointer pointer;
			if (parameters.TryGetAndRemove(context, "pointer", out pointer))
			{
				query.Add(new IsPropertyEqualSpecification("id", pointer.Id));
				counter++;
			}

			// check for ambigous parameters
			if (counter > 1)
				throw new InvalidOperationException("Detected an ambigious id parmeters. Remove either id, guid or pointer.");
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:36,代码来源:IdArgumentProcessor.cs

示例2: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			// parse the sorts and add them to the query
			string sortString;
			if (parameters.TryGetAndRemove(context, "sort", out sortString) && !string.IsNullOrEmpty(sortString))
				query.Add(Sort.Parse(sortString));
			else
				query.Add(Sort.DefaultSort);
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:15,代码来源:SortArgumentProcessor.cs

示例3: TestSimpleLikeQuery2

        public void TestSimpleLikeQuery2()
        {
            Query query = new Query();
            query.Add(Criterion.Create<Products>(t => t.ProductId, 2, CriteriaOperator.Greater), QueryOperator.And);
            query.Add(Criterion.Create<Products>(t => t.ProductId, 4, CriteriaOperator.LesserThan));

            string result = QueryTranslator.TranslateIntoSqlQuery(query, PRODUCT_SCRIPT);
            Assert.IsTrue(result == "exec sp_executesql N'select * from [Production].[Product] where (ProductId > @0 and ProductId < @1)', N'@0 nvarchar(4000), @1 nvarchar(4000)', @0 = N'2', @1 = N'4'");
        }
开发者ID:jsucupira,项目名称:dynamic-querying,代码行数:9,代码来源:SqlQueryTest.cs

示例4: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			// if the authorization is bypassed do not add the security check
			// TODO: add validator logic to make sure the type supports authorization
			bool bypassAuthorization;
			if (parameters.TryGetAndRemove(context, "bypassAuthorization", out bypassAuthorization) && bypassAuthorization)
				query.Add(AllowedRolesSpecification.Any());
			else
				query.Add(AllowedRolesSpecification.UserRoles(context));
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:16,代码来源:AllowedRolesQueryArgumentProcessor.cs

示例5: BuildQuery

        public override void BuildQuery(Query query)
        {
            base.BuildQuery(query);

            query.Add("raw");

            if (Index.HasValue)
            {
                query.Add("index", Index);
            }
        }
开发者ID:fallin,项目名称:cerulean-consul,代码行数:11,代码来源:KeyValueGetRawOptions.cs

示例6: FindAllCustomersOrdersWithInOrderDateBy

        public IEnumerable<Order> FindAllCustomersOrdersWithInOrderDateBy(Guid customerId, DateTime orderDate)
        {
            IEnumerable<Order> customerOrders = new List<Order>();

            Query query = new Query();
            query.Add(new Criterion("CustomerId", customerId, CriteriaOperator.Equal));
            query.QueryOperator = QueryOperator.And;
            query.Add(new Criterion("OrderDate", orderDate, CriteriaOperator.LessThanOrEqual));
            query.OrderByProperty = new OrderByClause { PropertyName = "OrderDate", Desc = true };

            customerOrders = _orderRepository.FindBy(query);

            return customerOrders;
        }
开发者ID:Defcoq,项目名称:Enterprise.Dev.Best.Practices,代码行数:14,代码来源:OrderService.cs

示例7: BuildQuery

        public override void BuildQuery(Query query)
        {
            base.BuildQuery(query);

            if (Recurse)
            {
                query.Add("recurse");
            }

            if (CheckAndSet.HasValue)
            {
                query.Add("cas", CheckAndSet);
            }
        }
开发者ID:fallin,项目名称:cerulean-consul,代码行数:14,代码来源:KeyValueDelOptions.cs

示例8: BuildQuery

 public virtual void BuildQuery(Query query)
 {
     if (!string.IsNullOrEmpty(DataCenter))
     {
         query.Add("dc", DataCenter);
     }
 }
开发者ID:fallin,项目名称:cerulean-consul,代码行数:7,代码来源:KeyValueOptions.cs

示例9: BuildQuery

        public override void BuildQuery(Query query)
        {
            base.BuildQuery(query);

            query.Add("keys");

            if (Index.HasValue)
            {
                query.Add("index", Index);
            }

            if (Separator.HasValue)
            {
                query.Add("separator", Separator);
            }
        }
开发者ID:fallin,项目名称:cerulean-consul,代码行数:16,代码来源:KeyValueGetKeysOptions.cs

示例10: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			// get the type name is any
			string typeNames;
			if (!parameters.TryGetAndRemove(context, "type", out typeNames) && string.IsNullOrEmpty(typeNames))
				return;

			// parse the type names
			var types = typeNames.Split(',').Select(x => typeService.Load(context, x)).ToArray();
			if (types.Length == 0)
				return;

			// add the type hints to the query
			query.Add(types);
			query.Add(new IsPropertyInSpecification("type", types.Select(type => type.Name)));
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:22,代码来源:TypeArgumentProcessor.cs

示例11: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			// check for the cache flag
			object tmp;
			if (parameters.TryGetAndRemove(context, StorageOnlyQueryComponent.PropertyKey, out tmp))
				query.Add(new StorageOnlyQueryComponent());
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:13,代码来源:StorageOnlyArgumentProcessor.cs

示例12: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			// check for search
			string where;
			if (parameters.TryGetAndRemove(context, "fts", out where) && !string.IsNullOrEmpty(where))
				query.Add(new FullTextSearchSpecification(where));
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:13,代码来源:FullTextSearchQueryArgumentProcessor.cs

示例13: DoProcess

		/// <summary>
		/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parameters">The parameters which to process.</param>
		/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
		protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
		{
			var clauseCounter = 0;

			// get the depth
			var depthValue = new Lazy<int?>(() =>
			                                {
			                                	int? depth = 1;
			                                	string depthString;
			                                	if (parameters.TryGetAndRemove(context, "depth", out depthString))
			                                	{
			                                		// check for any
			                                		if ("any".Equals(depthString, StringComparison.OrdinalIgnoreCase))
			                                			depth = null;
			                                		else
			                                		{
			                                			// parse the depth
			                                			depth = conversionService.Convert(context, depthString, 1);
			                                		}
			                                	}
			                                	return depth;
			                                });

			// check for parentPointer
			NodePointer parentPointer;
			if (parameters.TryGetAndRemove(context, "childPointer", out parentPointer))
			{
				query.Add(ParentOfSpecification.Child(parentPointer, depthValue.Value));
				clauseCounter++;
			}

			// check for pointer
			Node parentNode;
			if (parameters.TryGetAndRemove(context, "childSource", out parentNode))
			{
				query.Add(ParentOfSpecification.Child(parentNode.Pointer, depthValue.Value));
				clauseCounter++;
			}

			// sort on depth if no explicit sort has been set
			if (clauseCounter > 0 && !parameters.Contains("sort"))
				query.Add(new SortQueryComponent(DefaultSort));

			// check for ambigous parameters
			if (clauseCounter > 1)
				throw new InvalidOperationException("Detected an ambigious parent of clause. Remove either childPointer or childSource.");
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:53,代码来源:ParentOfQueryArgumentProcessor.cs

示例14: TestSimpleContainQuery

        public void TestSimpleContainQuery()
        {
            Query query = new Query();
            query.Add(Criterion.Create<Products>(t => t.ProductNumber, "CA-5965", CriteriaOperator.Equal));

            string result = QueryTranslator.TranslateIntoSqlQuery(query, PRODUCT_SCRIPT);
            Assert.IsTrue(result == "exec sp_executesql N'select * from [Production].[Product] where (ProductNumber = @0)', N'@0 nvarchar(4000)', @0 = N'CA-5965'");
        }
开发者ID:jsucupira,项目名称:dynamic-querying,代码行数:8,代码来源:SqlQueryTest.cs

示例15: test_starts_with

        public void test_starts_with()
        {
            Query query = new Query();
            query.Add(Criterion.Create<Products>(t => t.Name, "Chainring", CriteriaOperator.StartWith));

            string result = QueryTranslator.TranslateIntoSqlQuery(query, PRODUCT_SCRIPT);
            Assert.IsTrue(result == "exec sp_executesql N'select * from [Production].[Product] where (Name like @0 + ''%'')', N'@0 nvarchar(4000)', @0 = N'Chainring'");
        }
开发者ID:jsucupira,项目名称:dynamic-querying,代码行数:8,代码来源:SqlQueryTest.cs


注:本文中的Query.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。