Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3440562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:26:48+00:00 2026-05-18T08:26:48+00:00

I have a document class that contains a list of tags. Something like: class

  • 0

I have a document class that contains a list of “tags”. Something like:

class Item {
  string Name { get; set; }
  List<string> Tags {get; set;}
}

Now I would like to create a query for RavenDB that hands me all items filtered by a list of tags. When using Entity Framework I managed to do this by something like this:

var query = GetQueryable();
foreach (var tag in tags)
{
   query = query.Where(i => i.Tags.Contains(tag));
}

However, this doesn’t seem to work with RavenDB, most likely because Contains isn’t supported.. I’ve also tried rewriting it using Any, (Where(i => i.Tags.Any(t=>t == tag))) but that gives me a strange exception:

Unable to cast object of type
'System.Linq.Expressions.PrimitiveParameterExpression`1[System.String]'
to type 'System.Linq.Expressions.MemberExpression

Any great ideas? Am I doing this completely wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:26:48+00:00Added an answer on May 18, 2026 at 8:26 am

    Contains is indeed not yet supported (Perhaps it should be, but that’s another matter entirely – we only really add support for various operators when its asked for)

    As for multiple queries against Any, I assume you’re trying to do dynamic data and you want to achieve something like

    "X OR Y OR Z"
    

    That’s a tricky one, and the LINQ provider by default will aggregate those multiple WHERE clauses with AND, so your example looks like

    "X AND Y AND Z"
    

    Which will obviously never be the case.

    Your best option for this one is to drop down to the Lucene query (at least for now) and do something like this:

    var results = s.Advanced.LuceneQuery<Item>()
                       .Where(string.Format("Tags,:({0})", string.Join(" OR ", tags))); 
    

    Make sense?

    The query above will look something like

    "Tags,:(X OR Y OR Z)"
    

    Note: “Tags,” informs RavenDB that Tags is an array

    Okay, [edit]!

    The easiest way to get what you actually want is to do something along these lines

                    new IndexDefinition<Item, Item>()
                    {
                        Map = docs => from doc in docs
                                      select new
                                      {
                                          Tags = doc.Tags
                                      },
                        Indexes = {{ x => x.Tags, FieldIndexing.Analyzed }}
                    }.ToIndexDefinition(store.Conventions));
    

    Then to query for your ands, you can do something like this:

                    var results = s.Advanced.LuceneQuery<Item, WhateverYouCalledThatIndex>()
                       .Where(string.Format("Tags:({0})", string.Join(" AND ", tags)));
    

    Now, things to be aware of

           Tags = doc.Tags
    

    Will serialize that entire array into one giant blob, as it’s just strings that will work for this example.

    I am looking at better ways of expressing this, it is unlikely that we’ll come up with a LINQ-ish way of doing this, as it doesn’t really map across very well – but it is an answer that will work 🙂

    I think I’d quite like to be able to at least do

      Map = docs => from doc in docs
                                      select new
                                      {
                                          Tags = String.Join(" ", doc.Tags)
                                      },
    

    (This won’t work so don’t try it), but it is a bit more explicit about what you want to achieve.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
Problem: I have a document class which contains a list of objects. These objects
I have an XML document (generated by Adobe XFA forms), that contains data like
I need to add a class to the list item that matches document.title. My
I have a C# class method that return a xml document not file. How
I have a class as follows: public class Document { public List<DocumentSection> sections =
i have a List<my_Custom_Class> and List<string> . My custom class has various items in
I have an xml document that contains some html. <begin-line> <verse-num>6</verse-num>a mixed people<footnote id=f2>
I have a few objects in my class List<string> a List<string> b Dictionary<string,string> c
I have an XML configuration file that contains a list of documents with field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.