本文整理汇总了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.");
}
示例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);
}
示例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'");
}
示例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));
}
示例5: BuildQuery
public override void BuildQuery(Query query)
{
base.BuildQuery(query);
query.Add("raw");
if (Index.HasValue)
{
query.Add("index", Index);
}
}
示例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;
}
示例7: BuildQuery
public override void BuildQuery(Query query)
{
base.BuildQuery(query);
if (Recurse)
{
query.Add("recurse");
}
if (CheckAndSet.HasValue)
{
query.Add("cas", CheckAndSet);
}
}
示例8: BuildQuery
public virtual void BuildQuery(Query query)
{
if (!string.IsNullOrEmpty(DataCenter))
{
query.Add("dc", DataCenter);
}
}
示例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);
}
}
示例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)));
}
示例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());
}
示例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));
}
示例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.");
}
示例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'");
}
示例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'");
}