Raven DB

I’ll probably start a series of posts related to RavenDB, since I’m learning to use it. And here is the first one.

I’ve been using SQL queries most of my programmers life and I’m so used to ask database things like this: show me all projects that user has access to.

Or Select * from project where ProjectId in (select ProjectId from UserPermissions where UserId=1)

When you try to use the same logic in RavenDB, it throws you NotSupportedException and no hints of how to do it. Luckily, RavenDb is popular enough to have a good hit score in Google and I managed to find the answer on the interwebs pretty quick.

Here is the way to search in a subset:

#!csharp
var locations = ravenSession
    .Query<Location>()
    .Where(l => l.ProjectId.In<string>(currentUser.ProjectIds))
    .ToList();

And you’ll have to add using Raven.Client.Linq; to your class, so In<> becomes available.