Matt
Matt

Reputation: 2851

RavenDB query Store

Just got to grips with RavenDB - which is awesome - however I am getting a little stuck with a query. I running a foreach and using the Store() method to save some data and once complete using the SaveChanges() method.

Once I have stored this information, I need to reference this information to store some additional information (don't worry if you slightly confused at this point the code will make it clear!) but when I reference the information there is no information to be found.

So, first of all I add some data:

foreach (var development in developments)
            {
                Console.WriteLine(" - Working on Developmnent ID: " + development.devID);
                Session.Store(new Domain.Development
                                  {
                                      Id = "D" + Convert.ToString(development.devID),
                                      Name = development.devName,
                                      Street = development.devStreet,
                                      Town = development.devTown,
                                      County = development.devCounty,
                                      Postcode = development.devPostcode,
                                      Country = development.devCounty,
                                      Description = "",
                                      Longitude = GeoData.Longitude(development.devPostcode),
                                      Latitude = GeoData.Latitude(development.devPostcode)
                                  });

            }

Now, because of the limitations with the number of queries that can be ran within the session, I retrieve the whole dataset and store in memory:

var developmentList = from d in Session.Query<Domain.Development>()
                      select d;

Now when I add a break point at the end of this there is no data to be found. Do I need to create another session to retrieve this data?

I have also tried

var developmentList = Session.Query<Domain.Development>();

Here is the code where I create the session too:

internal static DocumentStore Store;
internal static IDocumentSession Session { get; set; }

internal <<Constructor>> ...
Store = new DocumentStore { ConnectionStringName = "RavenDB" };
Store.Initialize();

IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), Store);

Session = Store.OpenSession();

Upvotes: 1

Views: 224

Answers (2)

Ayende Rahien
Ayende Rahien

Reputation: 22956

If you just stored those values, why do you need to save them to the database and the re-load them from the database? Just use the in memory collection and that would be it.

Upvotes: 1

ZVenue
ZVenue

Reputation: 5027

It's not recommended you do this. Goes back to safe by default concept of RavenDB.

Upvotes: 1

Related Questions