Raven.Client.Shard.ShardedDocumentStore.OpenAsyncSession C# (CSharp) Method

OpenAsyncSession() public method

Opens the async session.
public OpenAsyncSession ( ) : IAsyncDocumentSession
return IAsyncDocumentSession
		public override IAsyncDocumentSession OpenAsyncSession()
		{
			return OpenAsyncSessionInternal(null, ShardStrategy.Shards.ToDictionary(x => x.Key, x => x.Value.AsyncDatabaseCommands));
		}

Same methods

ShardedDocumentStore::OpenAsyncSession ( string databaseName ) : IAsyncDocumentSession

Usage Example

Example #1
0
        public async Task DeleteItemOnAsyncShardedDocumentSession()
        {
            var server1 = GetNewServer(8079);
            var server2 = GetNewServer(8078);
            var shards = new Dictionary<string, IDocumentStore>
            {
                {"Shard1", new DocumentStore {Url = server1.Configuration.ServerUrl}},
                {"Shard2", new DocumentStore {Url = server2.Configuration.ServerUrl}},
            };

            var shardStrategy = new ShardStrategy(shards);
            shardStrategy.ShardingOn<Profile>(x => x.Location);

            using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
            {
                shardedDocumentStore.Initialize();

                var profile = new Profile { Name = "Test", Location = "Shard1" };
                var profile2 = new Profile { Name = "Test2", Location = "Shard2" };

                using (var documentSessionAsync = shardedDocumentStore.OpenAsyncSession())
                {
                    await documentSessionAsync.StoreAsync(profile, profile.Id);
                    await documentSessionAsync.StoreAsync(profile2, profile2.Id);
                    await documentSessionAsync.SaveChangesAsync();

                    documentSessionAsync.Delete(profile);
                    await documentSessionAsync.SaveChangesAsync();

                    var doc = documentSessionAsync.LoadAsync<Profile>(profile.Id);
                    Assert.Null(await doc);

                }

                using (var documentSessionAsync = shardedDocumentStore.OpenAsyncSession())
                {
                    Assert.Null(await documentSessionAsync.LoadAsync<Profile>(profile.Id));

                }
            }
        }
All Usage Examples Of Raven.Client.Shard.ShardedDocumentStore::OpenAsyncSession