1
votes

How do I get Odata working with a List variable? The following API is not working and giving error.

HttpGet

Error: {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00-b0b48a41f445ac4bbcebba902f8cca95-a714db4f4fd0c146-00"}

All my other APIs work,

"http://localhost:4547/api/properties/GetIdentifierPaged"

Controller:

[HttpGet[("[Action]")] 
public ActionResult GetIdentifierPaged(List<string> propertyListRequest, ODataQueryOptions<PropertyDto> queryOptions)
{
    propertyListRequest.Add("1110200100"); // fake data
    var model =  _propertyService.GetByPropertyIdentifierPaged(propertyListRequest).ToODataPageResult(queryOptions);
    return Ok(model);
}

Service:

public IQueryable<PropertyDto> GetByPropertyIdentifierPaged(List<string> identifiers)
{
    var identifiersEnumerable = identifiers.AsEnumerable();
    var properties = _dataContext.Property
        .Include(x => x.PropertyStatus)
         Where(x => identifiersEnumerable.Contains(x.PropertyIdentifier))
    return properties;
}

Page Result:

public static PageResult<T> ToODataPageResult<T>(this IQueryable<T> query, ODataQueryOptions<T> queryOptions)
{
    var settings = new ODataQuerySettings();
    settings.EnsureStableOrdering = false;
    var countQuery = (IQueryable<T>)queryOptions.ApplyTo(query, settings, AllowedQueryOptions.Skip | AllowedQueryOptions.Top | AllowedQueryOptions.Select | AllowedQueryOptions.OrderBy);
    long count = countQuery.Count();
    var results = (IQueryable<T>)queryOptions.ApplyTo(query, settings, AllowedQueryOptions.None);

    return new PageResult<T>(results, null, count);
}
1
Try casting your list .AsQueryable() - Jim Wooley

1 Answers

0
votes

This problem indicates that there is a problem with your request, but even if you came to respond, there are errors you will receive. You cannot give a value that session is open in response

return new PageResult<T>(**results.ToList()**, null, count);