Created
February 3, 2013 18:46
-
-
Save kijanawoodard/4703088 to your computer and use it in GitHub Desktop.
Per instance id increments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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