I am using ArangoDB and I am querying a collection named movies
. Its data structure is such that categories
is a List of strings.
public class movies
{
[DocumentProperty(Identifier = IdentifierType.Key)]
public string Key;
public List<string> categories;
public string desc;
public string img;
public List<vod_stream> streams;
public string title;
};
Here is the query statement:
var result = db.Query<movies>()
.Where(p => p.categories.Contains(id));
id
is passed as a param and I need to retrieve all the movies that has the category matched by the id.
However, above code doesn't work as result
gives me ALL the movies in the collection.
foreach (movies mov in result)
{
if (mov.categories.Contains(id) == false)
{ continue; }
// do something here
}
The weird thing is when I loop through the items in the result, the same function does return false
for some of the items. But it just doesn't work in the Linq statement.
Anybody knows what is wrong with my query statement?
The Linq Contains Method in C# is used to check whether a sequence or collection (i.e. data source) contains a specified element or not. If the data source contains the specified element, then it returns true else return false.
To check for an element in a string, use the Contains() method. The following is our string array. string[] arr = { "Java", "C++", "Python"}; Now, use Contains() method to find a specific string in the string array.
List<T>. Contains(T) Method is used to check whether an element is in the List<T> or not.
Select(x => new { x, count = x. tags. Count(tag => list. Contains(tag)) }) .
For using AQL Functions in ArangoDB LINQ provider you should use ArangoDB.Client.AQL
static methods.
For your use-case you can use in
AQL function:
var result = db.Query<movies>()
.Where(p => AQL.In(id, p.categories))
.ToList();
which translates to :
for `p` in `movies` filter @P1 in `p`.`categories` return `p`
Built-in methods for c# data structures like List
are not currently supported in ArangoDB LINQ provider
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With