OData / OData/AspNetCoreOData

Collection querying via EF7 JSON column

Open
#816 5 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Jan 20, 2023.

follow-up
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Not sure if this is just not supported yet or I'm doing something wrong

I have a List of Addresses stored in database as a JSON array
[{"StreetAddress":"1615 Anzac Avenue","City":"Kallangur","State":"QLD","Postcode":"4503","Latitude":-27.24795613,"Longitude":153.01077159},{"StreetAddress":"1611 Anzac Avenue","City":"Kallangur","State":"QLD","Postcode":"4503","Latitude":-27.24779426,"Longitude":153.01015158}]

I've mapped this using the new Entity Framework 7 JSON column support
When I query it via OData the results return as expected
However when I try to use any filter on the collection I get LINQ expression errors:

e.g. $filter=Addresses/$count gt 0
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The LINQ expression 'DbSet<ApplicationODataRecord>() .Where(a => EF.Property<List<Address>>(a, "Addresses") .AsQueryable() .LongCount() > __TypedProperty_0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

e.g. $filter=Addresses/any(a: a/Postcode eq '4503')
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The LINQ expression 'DbSet<ApplicationODataRecord>() .Where(a => EF.Property<List<Address>>(a, "Addresses") .AsQueryable() .Any(o => (string)o.Postcode == __TypedProperty_0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.