JsonContains and sub-properties
See original GitHub issueIs there a support for querying by a sub-property of an object within a collection? For example, I have the following classes defined
public class MyEntity
{
[Column("Info", TypeName = "jsonb")]
public Info Info { get; set; }
}
public class Info
{
public List<Tag> Tags { get; set; }
}
public class Tag
{
public int TagId { get; set; }
public int OtherData { get; set; }
}
How do I find all the MyEntity rows that have at least one Tag with TagId = 10 ? Here’s what I’ve tried so far:
// didn't work
var result = db.MyEntities.Where(m => EF.Functions.JsonContains(m.Info.Tags.Select(t => t.TagId), "10") ).ToList();
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
MySQL use JSON_CONTAINS with a subquery
You could just concat the double quotes in the subquery: SELECT * FROM addresses WHERE JSON_CONTAINS( `groups`, (SELECT CONCAT('"', u.group, ...
Read more >How to unnest / extract nested JSON data in MySQL 8.0
For DB users who work with JSON string in MySQL 8.0, a guide on how to unnest, flatten, and extract nested JSON data...
Read more >How to read nested JSON files and convert to case class ...
First, we need to understand our data structure. File climate-fever.json contains three properties (key-value pairs), animal_claims, ...
Read more >Use MySQL JSON field in Laravel - QCode
JSON_CONTAINS () function accepts the JSON field being searched and another to compare against. It returns 1 when a match is found, e.g....
Read more >JSON nested objects
JSON nested objects ... Objects can be nested inside other objects. Each nested object must have a unique access path. The same field...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@grcd that checks whether the entire Tags sub-document exists as provided, so it checks whether there’s only one tag with ID 10 (any additional tag will cause this to return false).
What if:
?