Linq list contains

I am using ArangoDB and I am requesting a collection with a name movies. Its data structure is such that it categoriesis 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 request:

var result = db.Query<movies>()
            .Where(p => p.categories.Contains(id));

idpassed as a parameter, and I need to get all movies that have a category corresponding to id. However, the code above does not work, as it resultgives me ALL the movies in the collection.

foreach (movies mov in result)
{
    if (mov.categories.Contains(id) == false)
    { continue; }

    // do something here
}

It is strange when I look at elements as a result, the same function returns falsefor some elements. But that just doesn't work in the Linq statement.

Does anyone know what is wrong with my query operation?

+6
source share
3 answers

AQL Functions LINQ ArangoDB ArangoDB.Client.AQL.

in AQL:

var result = db.Query<movies>()
                .Where(p => AQL.In(id, p.categories))
                .ToList();

:

for `p` in `movies`  filter  @P1 in `p`.`categories`  return   `p`

#, List, ArangoDB LINQ

+5

LINQ . LINQ , . , , LINQ .

, , , , foreach , .

docs arrangodb, , :

int age =  db.Query<Person>()
                  .Where(p => AQL.Contains(p.Name, "raoof"))
                  .Select(p => p.Age)
                  .FirstOrDefault();

, AQL.Contains - LINQ-to-SQL, SQLServer. id AQL.<something>, , . , , , . -

var result = db.Query<movies>()
        .Where(p => AQL.Contains(p.categories,id));
+3

When I added a quick code, this works

public void GetMoviesByCategory()
    {

        List<Movies> movies = new List<Movies>();
        movies.Add(new Movies(){moviename = "A", category = new List<String>(){"1","2"}});
        movies.Add(new Movies(){moviename = "B", category = new List<String>(){"2","3"}});
        movies.Add(new Movies(){moviename = "C", category = new List<String>(){"3","4"}});
        movies.Add(new Movies(){moviename = "D", category = new List<String>(){"1"}});
        movies.Add(new Movies(){moviename = "E", category = new List<String>(){"4"}});
        movies.Add(new Movies(){moviename = "F", category = new List<String>(){"1","2","4"}});
        var result = movies.Select(m => m).Where(p => p.category.Contains("1")).ToList();

        foreach(var movie in result){
            Console.WriteLine(movie.moviename);
        }
    }
    public class Movies{

        public Movies(){}
        public string moviename {get;set;}
        public List<string> category {get;set;}
    }
-1
source

All Articles