Skip to content

Instantly share code, notes, and snippets.

@kijanawoodard
Created February 3, 2013 18:46
Show Gist options
  • Save kijanawoodard/4703088 to your computer and use it in GitHub Desktop.
Save kijanawoodard/4703088 to your computer and use it in GitHub Desktop.
Per instance id increments
public interface IGenerateMyId
{
string GenerateId();
}
//This is used within my IoC registration; could be wherever you setup doc store
public RavenDbRegistry(string connectionStringName)
{
...
var generator = new MultiTypeHiLoKeyGenerator(documentStore, 32);
documentStore.Conventions.DocumentKeyGenerator = entity =>
{
var special = entity as IGenerateMyId;
return special == null ? generator.GenerateDocumentKey(documentStore.Conventions, entity) : special.GenerateId();
};
...
}
public class Registration : IGenerateMyId
{
public string CompanyId { get; set; }
...
public static string FormatId(string companyId)
{
var result = string.Format("{0}/registration/", companyId);
return result;
}
public string GenerateId()
{
return FormatId(CompanyId);
}
...
}
public class RegistrationController : RavenController
{
public ActionResult Index(string id)
{
//assuming id is the company id
//this LoadStartingWith is an extension method i'm using with 960
var registrations =
RavenSession
.LoadStartingWith<Registration>(Registration.FormatId(id));
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment