private void Init(CloudStorageAccount storageAccount) { _domainEventContext = new CloudTableContext<DomainEvent>(storageAccount, AggregateRootIdPropName); _latestVersionPartition = _domainEventContext.CreatePartitionSchema("LatestVersionPartition") .SetRowKeyCriteria(domainEvt => domainEvt.AggregateRootId.SerializeToString()) .SetSchemaCriteria(domainEvt => true) .SetIndexedPropertyCriteria(domainEvt => domainEvt.Sequence); _domainEventContext.AddPartitionSchema(_latestVersionPartition); }
/// <summary> /// The partition schemas are how your domain object gets sorted/categorized/grouped inside Azure Table /// storage. You create them in your client code and then "add" them to the CloudTableContext class /// that you're using to interact with the Table (in this case _userContext). /// Remember, these are just schema definitions for one particular PartitionKey. /// /// There is a DefaultSchema that get set on the CloudTableContext class automatically (in this case _userContext) /// which sets the PartitionKey to be the name of the object Type and the RowKey based on the Id property of the object /// provided during intialization. /// </summary> private void InitPartitionSchemas() { _usersInFloridaPartitionSchema = UserContext.CreatePartitionSchema() .SetPartitionKey("UsersInFlorida") .SetSchemaCriteria(user => user.UserAddress.State == "FL") /*The RowKey is set to the ID property by default, which in this case is the user.UserId*/ .SetIndexedPropertyCriteria(user => user.UserAddress.State); _firstNamePartitionSchema = UserContext.CreatePartitionSchema() .SetPartitionKey("FirstName") .SetSchemaCriteria(user => true) /*The RowKey is set to the ID property by default, which in this case is the user.UserId*/ .SetIndexedPropertyCriteria(user => user.FirstName); _userTypePartitionSchema = UserContext.CreatePartitionSchema() .SetPartitionKey("UserTypePartition") .SetSchemaCriteria(user => true) /*The RowKey is set to the ID property by default, which in this case is the user.UserId*/ .SetIndexedPropertyCriteria(user => user.GetType().Name); _userVersionPartitionSchema = UserContext.CreatePartitionSchema() .SetPartitionKey("UserVersionPartition") .SetSchemaCriteria(user => true) .SetRowKeyCriteria(user => UserContext.GetChronologicalBasedRowKey()) /*In this case we're keeping a version log so we want a new RowKey created upon each write to the Table*/ .SetIndexedPropertyCriteria(user => user.UserId); // Now add the schemas that were just created to the CloudTableContext<User> instance (i.e. _userContext). UserContext.AddMultiplePartitionSchemas(new List<PartitionSchema<User>> { _usersInFloridaPartitionSchema, _firstNamePartitionSchema, _userTypePartitionSchema, _userVersionPartitionSchema }); }