3

As I understand, ravendb uses the CLR type of an object in order to determine the Raven-Entity-Name metadata. For instance, saving an object of type Spoon would result in a Spoon document being created and added to the collection of spoons on the raven server.

Below are a couple of simple examples to help explain what I mean.

This will store an item in the 'ExpandoObjects' collection

dynamic item1 = new ExpandoObject();

item1.Id = "item/100"
item1.Cost = "£10";
item1.Color = "Silver";
//other properties relevant to the item being created

using (var session = this.documentStore.OpenSession()) 
{
    session.Store(item1);
    session.SaveChanges();
}

This will store an item in the 'items' collection:

Item item2 = new Item();

item2.Id = "item/101";
item2.Name = "Postcard";
item2.Cost = "£1";
item2.Material = "Card";

using (var session = this.documentStore.OpenSession()) 
{
    session.Store(item2);
    session.SaveChanges();
}

The first code block would store the item as an ExpandoObject in ravendb. But the behaviour that I would like is for raven to store it as an item, along with my strongly typed 'items', as shown in the second code block.

Is there a way to configure the DocumentStore so that it will use the left part of the Id field as the Raven-Entity-Name, rather than the ExpandoObject CLR type? Or is something like this not possible?

Thanks in advance.

Sam
  • 81
  • 1
  • 7
  • 1
    possible duplicate of [Specifying Collection Name in RavenDB](http://stackoverflow.com/questions/6969145/specifying-collection-name-in-ravendb) – Preston Guillot Feb 10 '15 at 16:52
  • Thank you Preston, didn't find that question when I searched. It answers my question! :) – Sam Feb 10 '15 at 16:55

0 Answers0