Replies: 3 comments
-
This is what I have right now. The filter is added to the query collection of the request, but somehow they aren't applied to the public async Task<IQueryable<TContract>> GetQueryableFromString<TEntity, TContract>(
string entitySetName,
string odataQuery,
Expression<Func<TEntity, bool>> filter = null,
QueryStrategy queryStrategy = QueryStrategy.AllFilters)
where TEntity : class
where TContract : class
{
IEdmModel model = ODataEdmModelProvider.BuildEdmModel();
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(entitySetName);
if (entitySet is null)
{
throw new Exception();
}
Type clrType = typeof(TContract);
List<ODataPathSegment> segments = new()
{
new EntitySetSegment(entitySet),
};
ODataPath path = new(segments);
ODataQueryContext context = new(model, clrType, path);
HttpRequest request = new DefaultHttpContext().Request;
Dictionary<string, StringValues> dictionary = new()
{
{ "filter", new StringValues(odataQuery) }
};
request.Query = new QueryCollection(dictionary);
ODataQueryOptions<TContract> options = new(context, request);
DbSet<TEntity> set = _dbSetProvider.DbSetOf<TEntity>();
IQueryable<TEntity> query = filter is null ? set.AsQueryable() : set.Where(filter);
return await query.GetQueryAsync(_mapper, options, _querySettings);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
@xuzhg I saw you replied on the original StackOverflow post, would you be able to help me out here? I would very much appreciate it. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Related to: #852 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My use case is as follows:
In the frontend application the user can build a complex OData filter which we then save in our database.
An AWS lambda function then needs to query the dataset using this saved filter (for example:
(assigneeId in ('8201014','3038351')) and (user/status eq 'active')
)I've been looking into instantiating
ODataQueryOptions
like described here, but it doesn't seem to work. I'm usingAutoMapper.AspNetCore.OData.EFCore 4.0.0
withMicrosoft.AspNetCore.OData 8.0.6
.Beta Was this translation helpful? Give feedback.
All reactions