Search code examples
c#databasenosqlravendbdocument-database

Using polymorphic queries over interfaces in RavenDB


I'm interested in switching over our application (or parts of it) to use RavenDB from SQL server with NHibernate.

The key feature that I can't seem to find in Raven is the usage of interfaces for queries eg:

ISearchable
{
  string Name {get;set;}
}

Class1 : ISearchable
{
  string Name {get;set;}
}
Class2 : ISearchable
{
   string Name {get;set;}
}

In NH I can search for the contents of the Name field in any ISearchable: QueryOver<ISearchable>().

I can't seem to find this in Raven, am I missing something? The closest that I've found is changing the string part at the front of the identifier, which I don't want to do; the main function of Class1 and Class2 is not to be searchable!

Thanks

Stu


Solution

  • Define an index like:

    // ByName
    from doc in docs
    select new { doc.Name }
    

    session.Query("ByName");