This project has moved. For the latest updates, please go here.

Test whether store exists first so I can configure "seed" data?

Jan 20, 2014 at 12:21 AM
I'm writing an application trying to use embedded BrightStarDB. Is there a way to tell when the context is created whether the store was created at the same time?

I'm trying to configure my application so that if the store is created for the first time, my code to "seed" some of the data will run. However, if the store already exists, I'm going to assume the database is already initialized with "seed" data.
Coordinator
Jan 20, 2014 at 1:00 PM
The best thing is to check before you create the EF context:
var client = BrightstarService.GetClient( /* connection string */);
bool storeAlreadyExists = client.DoesStoreExist("MyStore");

var context = // Make EF context

if (!storeAlreadyExists) {
  SeedStore(context);
}
Marked as answer by silverfox1948 on 3/8/2014 at 3:17 PM
Jan 25, 2014 at 9:28 PM
Techquila (nice play, by the way, on one of my favorite spirits ...)
Thanks. I notice you are referencing BrightstarService. This is for an embedded store. Will BrightstarService work on an embedded store? The name sort of implies it's expecting a service.

I did implement a simple check using System.IO libraries whether to store directory exists or not. It's not as "clean" as I would like, but it did work.
Coordinator
Jan 28, 2014 at 10:35 AM
The IBrightstarService interface just defines the contract for BrightstarDB services, so it is the same whether you are running embedded or client-server.

The embedded implementation of DoesStoreExist basically just does the same sort of file system check (although it checks for both the directory and a master.bs file inside the directory).
Feb 14, 2014 at 12:10 AM
Techquila,

I tried your suggestion and it worked fine for me. Much cleaner code! Thanks!