本文整理汇总了C#中System.Web.Http.OData.Query.ODataQueryOptions类的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryOptions类的具体用法?C# ODataQueryOptions怎么用?C# ODataQueryOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataQueryOptions类属于System.Web.Http.OData.Query命名空间,在下文中一共展示了ODataQueryOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: GetCount
public HttpResponseMessage GetCount(ODataQueryOptions<ODataPackage> options)
{
var queryResults = (IQueryable<ODataPackage>)options.ApplyTo(Get());
var count = queryResults.Count();
return OkCount(count);
}
示例3: GetReference
// GET: odata/References(5)
public async Task<IHttpActionResult> GetReference([FromODataUri] int key, ODataQueryOptions<Reference> queryOptions)
{
//Get access token to SharePoint
string accessToken = await _tokenProvider.GetSharePointAccessToken();
if (accessToken == null)
{
throw new UnauthorizedAccessException();
}
// validate the query.
try
{
queryOptions.Validate(_validationSettings);
}
catch (ODataException ex)
{
return BadRequest(ex.Message);
}
//Get reference from SharePoint
string eTag = Request.Headers.IfNoneMatch.ToString();
Reference reference = await _repository.GetReference(accessToken, key, eTag);
//Check eTag
if (reference.__eTag == eTag)
{
return new StatusCodeResult(HttpStatusCode.NotModified, Request);
}
return Ok(reference);
}
示例4: Get
public IHttpActionResult Get(int key, ODataQueryOptions<ETagsCustomer> queryOptions)
{
IEnumerable<ETagsCustomer> appliedCustomers = customers.Where(c => c.Id == key);
if (appliedCustomers.Count() == 0)
{
return BadRequest("The key is not valid");
}
if (queryOptions.IfNoneMatch != null)
{
appliedCustomers = queryOptions.IfNoneMatch.ApplyTo(appliedCustomers.AsQueryable()).Cast<ETagsCustomer>();
}
if (queryOptions.IfMatch != null)
{
appliedCustomers = queryOptions.IfMatch.ApplyTo(appliedCustomers.AsQueryable()).Cast<ETagsCustomer>();
}
if (appliedCustomers.Count() == 0)
{
return StatusCode(HttpStatusCode.NotModified);
}
else
{
return Ok(new SingleResult<ETagsCustomer>(appliedCustomers.AsQueryable()));
}
}
示例5: GetProject
// GET: odata/Projects(5)
public async Task<IHttpActionResult> GetProject([FromODataUri] int key, ODataQueryOptions<Project> queryOptions)
{
//Get access token to SharePoint
string accessToken = ((Repository)_repository).GetAccessToken();
if (accessToken == null)
{
throw new UnauthorizedAccessException();
}
// validate the query.
try
{
queryOptions.Validate(_validationSettings);
}
catch (ODataException ex)
{
return BadRequest(ex.Message);
}
//Get project from SharePoint
string eTag = Request.Headers.IfNoneMatch.ToString();
Project project = await _repository.GetProject(accessToken, key, eTag);
//Check eTag
if (project.__eTag == eTag)
{
return new StatusCodeResult(HttpStatusCode.NotModified, Request);
}
else
{
return Ok<Project>(project);
}
}
示例6: 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;
}
示例7: Get
/// <summary>
/// Gets the list of blog posts by specified filter.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>
/// List of blog post service models.
/// </returns>
public DataListResponse<AuthorModel> Get(ODataQueryOptions<AuthorModel> options)
{
using (var api = CmsContext.CreateApiContextOf<BlogsApiContext>())
{
var results = api.GetAuthorsAsQueryable();
return results.ToDataListResponse(options);
}
}
示例8: Get
/// <summary>
/// Gets the list of blog posts by specified filter.
/// </summary>
/// <param name="options">The options.</param>
/// <param name="filter">The filter.</param>
/// <returns>
/// List of blog post service models.
/// </returns>
public DataListResponse<BlogPostModel> Get(ODataQueryOptions<BlogPostModel> options, [FromUri] GetBlogPostRequest filter)
{
using (var api = CmsContext.CreateApiContextOf<BlogsApiContext>())
{
var results = api.GetBlogPostsAsQueryable(filter);
return results.ToDataListResponse(options);
}
}
示例9: ApplyQuery
/// <summary>
/// All standard OData web api support is handled here (except select and expand).
/// This method also handles nested orderby statements the the current ASP.NET web api does not yet support.
/// This method is called by base.OnActionExecuted
/// </summary>
/// <param name="queryable"></param>
/// <param name="queryOptions"></param>
/// <returns></returns>
public override IQueryable ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
{
var queryHelper = GetQueryHelper(queryOptions.Request);
queryable = queryHelper.BeforeApplyQuery(queryable, queryOptions);
queryable = queryHelper.ApplyQuery(queryable, queryOptions);
return queryable;
}
示例10: 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);
}
示例11: BeforeApplyQuery
public override IQueryable BeforeApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
{
var nhQueryable = queryable as IQueryableInclude;
if (nhQueryable != null)
{
queryable = ApplyExpand(nhQueryable);
}
return queryable;
}
示例12: 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>;
}
示例13: 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);
}
示例14: Get
public IHttpActionResult Get(ODataQueryOptions<V1FeedPackage> options)
{
var queryable = _packagesRepository.GetAll()
.Where(p => !p.IsPrerelease && !p.Deleted)
.WithoutVersionSort()
.ToV1FeedPackageQuery(_configurationService.GetSiteRoot(UseHttps()));
return QueryResult(options, queryable, MaxPageSize);
}
示例15: Ctor_SuccedsIfEntityTypesMatch
public void Ctor_SuccedsIfEntityTypesMatch()
{
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.Equal("10", query.Top.RawValue);
}