本文整理汇总了C#中System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryOptions.ApplyTo方法的具体用法?C# ODataQueryOptions.ApplyTo怎么用?C# ODataQueryOptions.ApplyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.OData.Query.ODataQueryOptions
的用法示例。
在下文中一共展示了ODataQueryOptions.ApplyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrders
// GET: odata/Orders
public async Task<IHttpActionResult> GetOrders(ODataQueryOptions<Order> queryOptions)
{
// validate the query.
try
{
queryOptions.Validate(_validationSettings);
}
catch (ODataException ex)
{
return BadRequest(ex.Message);
}
var repository = new Repositories.OrderMemoryRepository();
var orders = queryOptions.ApplyTo(repository.Get().AsQueryable<Order>());
return Ok<IQueryable<Order>>((IQueryable<Order>)orders);
}
示例2: GetCategoryTrees
public async Task<IHttpActionResult> GetCategoryTrees(ODataQueryOptions<CategoryTree> queryOptions)
{
logger.Trace("Call CategoryTreesController GetCategoryTrees");
try
{
queryOptions.Validate(_validationSettings);
}
catch (ODataException ex)
{
return BadRequest(ex.Message);
}
var data = await repository.All();
var query = (IQueryable<CategoryTree>)queryOptions
.ApplyTo(data.AsQueryable());
return Ok(query);
}
示例3: GetCount
public HttpResponseMessage GetCount(ODataQueryOptions<ODataPackage> options)
{
var queryResults = (IQueryable<ODataPackage>)options.ApplyTo(Get());
var count = queryResults.Count();
return OkCount(count);
}
示例4: Get
public IQueryable<ProductType> Get(ODataQueryOptions<Domain.ProductType> paramters)
{
var resultset = paramters.ApplyTo(_db.ProductTypes).AsQueryable() as IQueryable<Domain.ProductType>;
// ReSharper disable once AssignNullToNotNullAttribute
var productTypes = resultset.ToArray().Select(Mapper.Map<ProductType>).AsQueryable();
return productTypes;
}
示例5: IsHijackable
public static bool IsHijackable(ODataQueryOptions<V2FeedPackage> options, out HijackableQueryParameters hijackable)
{
// Check if we can process the filter clause
if (!CanProcessFilterClause(options))
{
hijackable = null;
return false;
}
// Build expression (this works around all internal classes in the OData library - all we want is an expression tree)
var expression = options.ApplyTo(EmptyQueryable, QueryResultDefaults.DefaultQuerySettings).Expression;
// Unravel the comparisons into a list we can reason about
List<Tuple<Target, string>> comparisons = new List<Tuple<Target, string>>();
Expression remnant = FindQueryableWhere(expression as MethodCallExpression);
MethodCallExpression where;
while (IsQueryableWhere(where = remnant as MethodCallExpression))
{
var extractedComparisons = ExtractComparison(where).ToList();
if (!extractedComparisons.Any() || extractedComparisons.Any(c => c == null))
{
hijackable = null;
return false;
}
else
{
// We recognize this comparison, record it and keep iterating on the nested expression
comparisons.AddRange(extractedComparisons);
remnant = where.Arguments[0];
}
}
// We should be able to hijack here
if (comparisons.Any())
{
hijackable = new HijackableQueryParameters();
foreach (var comparison in comparisons)
{
if (comparison.Item1 == Target.Id)
{
hijackable.Id = comparison.Item2;
}
else if (comparison.Item1 == Target.Version)
{
hijackable.Version = comparison.Item2;
}
else
{
hijackable = null;
return false;
}
}
return true;
}
hijackable = null;
return false;
}
示例6: GetSalesLeads
public IHttpActionResult GetSalesLeads(ODataQueryOptions<SalesLead> queryOptions)
{
try { queryOptions.Validate(_validationSettings); }
catch (ODataException ex) { return BadRequest(ex.Message); }
var queryResults = queryOptions.ApplyTo(SalesLeadFactory.GetSalesLeads()).Cast<SalesLead>();
return Ok<IQueryable<SalesLead>>(queryResults);
}
示例7: Get
// GET api/buildingupgrade
public IQueryable<BuildingUpgrade> Get(ODataQueryOptions<Domain.BuildingUpgrade> paramters)
{
var logStart = LogHelper.StartLog("Started BuildingUpgradeController.Get", Logger);
var resultset = paramters.ApplyTo(_db.BuildingUpgrades).AsQueryable() as IQueryable<Domain.BuildingUpgrade>;
// ReSharper disable once AssignNullToNotNullAttribute
var buildingUpgrades = resultset.ToArray().Where(x=>x.Name.StartsWith("Property") && x.Completed == false).OrderBy(x=>x.Name). Select(Mapper.Map<BuildingUpgrade>).AsQueryable();
return LogHelper.EndLog(logStart, buildingUpgrades);
}
示例8: GetPurchaseRequisitionDescriptions
// GET api/PurchaseRequisitionDescription
public IEnumerable<PurchaseRequisitionDescription> GetPurchaseRequisitionDescriptions(ODataQueryOptions Options)
{
//return db.PurchaseRequisitionDescriptions.Include(p=>p.Product).AsEnumerable();
//return Options.ApplyTo(db.PurchaseRequisitionDescriptions.Include(p => p.Product) as IQueryable) as IEnumerable<PurchaseRequisitionDescription>;
//db.PurchaseRequisitionDescriptions.Include(p => p.Product).Include()
return Options.ApplyTo(db.PurchaseRequisitionDescriptions.AsQueryable().Include(p => p.Product).Include(p => p.Product.ProductCategory).Include(u => u.UOM)) as IEnumerable<PurchaseRequisitionDescription>;
}
示例9: CountSearch
public HttpResponseMessage CountSearch(
[FromODataUri] string searchTerm,
[FromODataUri] string targetFramework,
[FromODataUri] bool includePrerelease,
ODataQueryOptions<ODataPackage> options)
{
var queryResults = (IQueryable<ODataPackage>)options.ApplyTo(Search(searchTerm, targetFramework, includePrerelease, options));
var count = queryResults.Count();
return OkCount(count);
}
示例10: ApplyTo_Succeeds_If_QueryTypeMatchesOptionsType
public void ApplyTo_Succeeds_If_QueryTypeMatchesOptionsType()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
ODataQueryContext context = new ODataQueryContext(builder.GetEdmModel(), typeof(Customer));
ODataQueryOptions<Customer> query = new ODataQueryOptions<Customer>(context, new HttpRequestMessage(HttpMethod.Get, "http://server/?$top=10"));
Assert.DoesNotThrow(
() => query.ApplyTo(Enumerable.Empty<Customer>().AsQueryable()));
}
示例11: ApplyTo_ThrowsInvalidOp_If_QueryTypeDoesnotMatch
public void ApplyTo_ThrowsInvalidOp_If_QueryTypeDoesnotMatch()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
ODataQueryContext context = new ODataQueryContext(builder.GetEdmModel(), typeof(Customer));
ODataQueryOptions<Customer> query = new ODataQueryOptions<Customer>(context, new HttpRequestMessage(HttpMethod.Get, "http://server/?$top=10"));
Assert.Throws<InvalidOperationException>(
() => query.ApplyTo(Enumerable.Empty<int>().AsQueryable()),
"Cannot apply ODataQueryOptions of 'System.Web.Http.OData.TestCommon.Models.Customer' to IQueryable of 'System.Int32'.");
}
示例12: Get
public IQueryable<LessonViewModel> Get(ODataQueryOptions<LessonViewModel> queryOptions)
{
var result = _lessonService.GetLessons().Select(l => new LessonViewModel
{
Date = l.Date,
GroupId = l.Group.GroupId,
LessonId = l.LessonId,
GroupDisplayName = l.Group.GroupNumber + " (" + l.Group.Year + ")"
});
var filteredResult = ((IQueryable<LessonViewModel>)queryOptions.ApplyTo(result));
return filteredResult;
}
示例13: GetOrders
public PageResult<Order> GetOrders(ODataQueryOptions<Order> options)
{
var settings = new ODataQuerySettings();
var fromDatabase = _context.Orders.Where(order => order.Freight != 123);
var results = options.ApplyTo(fromDatabase.AsQueryable(), settings);
return new PageResult<Order>(
results as IQueryable<Order>,
Request.ODataProperties().NextLink,
Request.ODataProperties().TotalCount);
}
示例14: GetFacets
public IQueryable<Facet> GetFacets(ODataQueryOptions<Car> options)
{
if (options.RawValues.Expand.IsNullOrEmpty())
{
return new Facet[0].AsQueryable();
}
IQueryable results = options.ApplyTo(SearchContext.GetQueryable<Car>());
string[] facets = StringUtil.Split(options.RawValues.Expand, '|', true);
var query = results as IQueryable<Car>;
return SearchService.GetFacets(query, facets);
}
示例15: GetCustomers
public IEnumerable<Customer> GetCustomers(ODataQueryOptions<Customer> queryOptions)
{
// validate the query.
queryOptions.Validate(_validationSettings);
// Apply the query.
IQuery query = queryOptions.ApplyTo(_db);
Console.WriteLine("Executing HQL:\t" + query);
Console.WriteLine();
return query.List<Customer>();
}