Ayende @ Rahien

It's a girl

Accessing RavenDB from Silverlight

The next build of RavenDB is going to include a major new feature, a Silverlight API. That comes in addition to our REST, .NET and JavaScript API.

What is means is that you can now just download RavenDB’s (the new bits are in the unstable fork right now) and start using it from Silverlight. Here is an example of how the code looks like:

var documentStore = new DocumentStore { Url = "http://localhost:8080" };
documentStore.Initialize();

var entity = new Company { Name = "Async Company #1", Id = "companies/1" };
using (var session = documentStore.OpenAsyncSession(dbname))
{
    session.Store(entity);
    session.SaveChangesAsync(); // returns a task that completes asynchronously

     var query = session.Query<Company>()
       .Where(x => x.Name == "Async Company #1")
       .ToListAsync();  // returns a task that will execute the query

In order to handle the Silverlight Asynchronous requirement, we have taken dependency on the Async CTP, which brings us support for TPL on Silverlight.

Overall, this make things a lot simpler all around, I think.

Comments

Ruben Bartelink
02/10/2011 09:56 AM by
Ruben Bartelink

Curious whether you considered the Reactive stuff as a way to manage the asynchrony, i.e., generating Observables instead of Tasks, and having people have to reference a DLL or two from that.

Admittedly it's conceptually heavier and not a minimal solution to the problem, but it's more 'released' than the Async CTP.

Are you talking just taking the DLLs and running (and assuming they'll make it into SL5) or using the compiler too?

But then released is in the eye of the beholder when it's not all sitting in a public repo I guess.

Ayende Rahien
02/10/2011 11:45 AM by
Ayende Rahien

Ruben,

I think that Reactive is much more complicated than the TPL.

And yes, I am talking about just the TPL, you don't need the compiler.

Not following what you mean by not in a public repo?

Ruben Bartelink
02/10/2011 01:17 PM by
Ruben Bartelink

Re public repo, I meant that the async CTP and the devlabs drops of RX are more or less equivalent in terms of usability for the world that doesnt want to get intimate with or take dependencies on release schedules:

a) whether they're final

b) whether one would expect to be able to see the source for <$35

c) whether one would expect to be able to send a patch

d) whether they can be expected to have a delivery mechanism that cant be broken by the release of ASP.NET MVC3

For others, the relevant DLL containing the TPL impl sits in <userprofiledir\Documents\Microsoft Visual Studio Async CTP\Samples after installation

jalchr
02/10/2011 01:44 PM by
jalchr

Why isn't the API consistent with non-silverlight code ... I think it should be like this

var entity = new Company { Name = "Async Company #1", Id = "companies/1" };

using (var session = documentStore.OpenSessionAsync(dbname))

{

session.Store(entity);

session.SaveChanges(); // returns a task that completes asynchronously


 var query = session.Query

<company()

   .Where(x => x.Name == "Async Company #1")

   .ToList();  // returns a task that will execute the query

}

Which might be used also in non-silverlight environments too ...

Ayende Rahien
02/10/2011 01:51 PM by
Ayende Rahien

Jalchr,

a) To match the C# coding standard for 5.0

b) Because methods with the same name that does different things are VERY bad

smart guy
02/10/2011 08:11 PM by
smart guy

Now that's a combination... Silverlight and RavenDB. Somehow I've got impression that the NoSQL guys are also the NoSilverlight guys. Am I being wrong?

Jimmy Zimmerman
02/11/2011 09:13 PM by
Jimmy Zimmerman

@Ruben

Rx is a great system no doubt but on the WCF layer of things the path forward is unequivocally TPL. End of debate. It makes sense therefore for Oren to take this route with the SL Raven DB client for no reason more than convention with the rest of the stack.

However that doesn't mean whatsoever that you cannot use Rx wrapped over TPL in your higher layers. There's some handy extension methods out there for doing just that. Simply put, IMHO Rx is best on the, well ..., reacting side of things. TPL is a better fit for the doing the thing itself.

Service Call = doing.

Updating the UI based on the call -> Rx to the rescue.

=D

Ruben Bartelink
02/14/2011 12:26 PM by
Ruben Bartelink

@Jimmy Zimmerman: Thanks for taking the time to lay it out that cleanly - makes sense.

I dont disagree with the perspective (reason I didnt respond to Ayende's response is that it's just correct!)

There's no doubt that, when compared to Rx, the Task <t stuff is

a) going to be native to SL in a future version

b) supported by he compiler enhacements

c) is simpler

d) is more likely to make it to the Phone (When you adding that, Oren? :P)

Therefore, unless one is going to get a significant benefit that outweighs the -100 points (@Raymond Chen) that adding another concept into the mix costs, sticking with the simplest thing definitely makes sense.

I was wondering purely about whether he'd considered/what his view was regarding the relative stability/availability of the relevant DLLs in question in the short to medium term and, implicit in that, whether he saw any angle/appropriateness for Rx when interacting with his lib making sense in any way.

Aaron Powell
02/15/2011 01:52 AM by
Aaron Powell

There's a JavaScript API?

James Webster
02/23/2011 01:16 AM by
James Webster

Does RavenDB support deployment to Azure just yet? I know a patch was in progress, has it hit the main build?

Ayende Rahien
02/23/2011 11:14 AM by
Ayende Rahien

James,

Yes, it does. It works a bit differently now, since we can be hosted in Azure, but it certainly works

Comments have been closed on this topic.