Returning multiple ids with Load()

60 views
Skip to first unread message

Starfish

unread,
Nov 19, 2012, 7:52:24 AM11/19/12
to rav...@googlegroups.com
I'm having trouble loading a bunch of documents that with known ids with a load operation.

Code is:

var savedThreads = session.Load<Thread>(requestBody.SavedIds);

Maps to:


Gives HTTP 200:

{
  • Results: [ ],
  • Includes: [ ]
}

But I have these documents! Raven build 2142.

Starfish

unread,
Nov 19, 2012, 8:28:38 AM11/19/12
to rav...@googlegroups.com
OK, I forgot the collection before id. Sorry everyone! :(

Felipe Leusin

unread,
Nov 19, 2012, 12:20:28 PM11/19/12
to rav...@googlegroups.com
I've made this mistake several times in the past. Never found an elegant way of doing it so I just wrote an extension method:

public static T[] Load<T>(this IDocumentSession session, ValueType[] ids)
        {
            var typeTagName = session.Advanced.DocumentStore.Conventions.GetTypeTagName(typeof (T));

            return session.Load<T>(ids.Select(x => string.Format("{0}/{1}", typeTagName, x)));
        }

I think it's something like this, just wrote this out of memory.

Chris Marisic

unread,
Nov 19, 2012, 12:47:21 PM11/19/12
to rav...@googlegroups.com
This is a rather naive method.

Taking the most advantage of raven as you can you will end up with documentIds like foo/1/bar/2/baz/3, even without rich document ids like that you really don't want to be dealing with id: "123" and trying to infer that to "contacts/123" you want to have "contacts/123" on hand.

Felipe Leusin

unread,
Nov 19, 2012, 2:20:53 PM11/19/12
to rav...@googlegroups.com
Just because it's naive doesn't mean it's not usefull on some situations.

I used it on a application where the Ids where the facebook profile Id (I needed a fast way to check if a user had been registered on RavenDb either by himself or as a friend of someone) and it was helpfull.

Chris Marisic

unread,
Nov 19, 2012, 2:30:10 PM11/19/12
to rav...@googlegroups.com
The issue with this is using methods like this as a standard practice you're going to fixate on id is 123, not that id really is "contacts/123" and that's a very bad choice in RavenDB IMO.

Chris Marisic

unread,
Nov 19, 2012, 2:32:35 PM11/19/12
to rav...@googlegroups.com
 Its fine if you're doing things like convert a sequence of facebook userIds to user/{facebookId} but outside of that scenario I'd say it's a value negative.
Reply all
Reply to author
Forward
0 new messages