[QUESTION] System.NotSupportedException: Any/All requires simple parameter on left side. - Querying nested array, how can I accomplish this?
See original GitHub issueLiteDB Version: 5.0.3
Hey guys, thanks for the work on LiteDB ! I am checking out if LiteDB might work for my use case. Thanks for the help!
My entities:
public class TagEntryModel
{
public int Id { get; set; }
public string Value { get; set; }
}
public class JobEntryModel
{
public int Id { get; set; }
public string Company { get; set; }
public string Title { get; set; }
public string Subtitle { get; set; }
public string Url { get; set; }
public DateTime Date { get; set; }
[BsonRef("JobEntryModel")] public List<TagEntryModel> Tags { get; set; } = new List<TagEntryModel>();
}
Basically I want to be able to filter out job entries by tags, title, company and then order by date. Is this possible? What I have right now is:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using LiteDB;
namespace LiteDbTestApp
{
class Program
{
static void TestQuery()
{
if (File.Exists("test.db"))
File.Delete("test.db");
using var db = new LiteDatabase("Filename=test.db;Connection=Direct");
var tagCollection = db.GetCollection<TagEntryModel>();
var jobCollection = db.GetCollection<JobEntryModel>();
var tag = new TagEntryModel {Value = "react"};
tagCollection.Insert(tag);
tagCollection.EnsureIndex(x => x.Value);
var job = new JobEntryModel
{Title = "random job title", Company = "random company", Tags = new List<TagEntryModel> {tag}};
jobCollection.Insert(job);
jobCollection.EnsureIndex(x => x.Tags);
var findTags = new List<string> {"react"};
var query = jobCollection.Query()
.Include(x => x.Tags)
.Where(x => x.Title.Contains("ti"))
.Where(x => x.Tags.Select(model => model.Value).Any(b => findTags.Contains(b)))
.OrderBy(x => x.Date)
.Limit(50);
var reader = query.ExecuteReader();
var entities = reader.ToList();
Console.WriteLine(entities.Count);
}
static async Task Main(string[] args)
{
TestQuery();
}
}
Right now I am getting the following exception thrown:
Unhandled exception. System.NotSupportedException: Any/All requires simple parameter on left side. Eg: x.Customers.Select(c => c.Name).Any(n => n.StartsWith('J'))
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Querying nested data with Amazon Redshift Spectrum
Step 1: Create an external table that contains nested data. Step 2: Query your nested data in Amazon S3 with SQL extensions. Nested...
Read more >How do i over lapping columns as nested array ? NodeJS ...
Actually, I'm trying to get my mysql result as nested array data i ... i need to use that function to convert those...
Read more >BigQuery: SQL on Nested Data
The magical function that allows us to query arrays is called UNNEST() . It takes an array as input and provides its contents...
Read more >Nested field type | Elasticsearch Guide [8.9]
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way...
Read more >Nested data in BigQuery (repeated records) | Looker
BigQuery supports nested records in tables. Nested records can be a single record or contain repeated values. This page provides an overview ...
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 FreeTop 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
Top GitHub Comments
@atresnjo About the index, in your example you wouldn’t be able to do anything relevant with
Tags
because it is a reference to another collection, and you can only index information pertaining to the same collection.Actually, I think it would be best for the Tags to be stored as embedded documents inside every
JobEntryModel
. It’s usually better to use embedded documents instead of references when modeling for a document-oriented database.@atresnjo The
BsonRef
attribute in Tags is wrong, it should be[BsonRef("TagEntryModel")]