Skip to content
This repository

Raven.DynamicSession is a dynamic session allowing you to use RavenDB without the need of POCOs.

branch: master
README.md

Raven.DynamicSession

Raven.DynamicSession is a dynamic session allowing you to use RavenDB without the need of POCOs.

The idea came up discussing APIs with prabir in https://jabbr.net and so I decided to see if I could come up with something that achieved what he wanted.

So far I have a working prototype that allows for you to create a Dynamic Session which you can Insert or Load dynamic objects.

using (dynamic session = documentStore.OpenDynamicSession())
{
    session.Posts.insert(new
    {
        Name = "Rabbit"
    }, "909");
    session.Posts.Insert(new
    {
        Name = "Banana"
    }, "123");
    session.People.insert(new
    {
        FirstName = "Phillip"
    }, "1");
    session.People.Insert(new
    {
        FirstName = "Prabir"
    }, "2");

    session.SaveChanges();
}

The above uses the dynamic property 'Posts' or 'people' as the document collection, then invokes a dynamic method which takes a parameter of data. In this case it takes 2 arguments, the object, and the Id. Currently I can't auto insert Ids but that may be possible in the future.

These objects are automatically inserted and it uses the property to set the Raven-Entity-Name to ensure they all end up in their own collections.

using (dynamic session = documentStore.OpenDynamicSession())
{
    dynamic post1 = session.Posts.load(123);
    Console.WriteLine(post1.Name);

    dynamic post2 = session.Posts.Load(909);
    Console.WriteLine(post2.Name);

    dynamic person1 = session.People.load(1);
    Console.WriteLine(person1.FirstName);

    dynamic person2 = session.People.Load(2);
    Console.WriteLine(person2.FirstName);
}

This code, like the previous code uses the property as the collection, and invokes the Load method from the normal RavenDB session, returning a dynamic type. At the moment it accepts an int for the Id and uses the property to construct the RavenDB document Id like: posts/123

I wouldn't recommend using this for any real world projects... yet, maybe in the future but this is very much a prototype project to see if it's even possible to achieve something like this.

Something went wrong with that request. Please try again.