当前位置: 首页>>代码示例>>C#>>正文


C# ShardedDocumentStore.OpenAsyncSession方法代码示例

本文整理汇总了C#中Raven.Client.Shard.ShardedDocumentStore.OpenAsyncSession方法的典型用法代码示例。如果您正苦于以下问题:C# ShardedDocumentStore.OpenAsyncSession方法的具体用法?C# ShardedDocumentStore.OpenAsyncSession怎么用?C# ShardedDocumentStore.OpenAsyncSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Client.Shard.ShardedDocumentStore的用法示例。


在下文中一共展示了ShardedDocumentStore.OpenAsyncSession方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteItemOnAsyncShardedDocumentSession

        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));

                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:41,代码来源:RavenDB_3938.cs

示例2: CanOverrideTheShardIdGeneration

		public void CanOverrideTheShardIdGeneration()
		{
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				foreach (var shard in shards)
				{
					shard.Value.Conventions.DocumentKeyGenerator = (cmds, c) => ((Company)c).Name;
				}

				using (var session = documentStore.OpenAsyncSession())
				{
					session.Store(company1);
					session.Store(company2);

					session.SaveChangesAsync().Wait();

					Assert.Equal("Shard1/companies/1", company1.Id);
					Assert.Equal("Shard2/companies/2", company2.Id);
				}
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:23,代码来源:WhenUsingShardedServers.cs

示例3: CanQueryUsingInt

		public void CanQueryUsingInt()
		{
			shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy();
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				using (var session = documentStore.OpenAsyncSession())
				{
					session.LoadAsync<Company>(1).Wait();
				}
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:13,代码来源:WhenUsingShardedServers.cs

示例4: CanGetAllShardedEntities

		public void CanGetAllShardedEntities()
		{
			//get them in simple single threaded sequence for this test
			shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy();

			using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize())
			using (var session = documentStore.OpenAsyncSession())
			{
				//store 2 items in 2 shards
				session.Store(company1);
				session.Store(company2);

				session.SaveChangesAsync().Wait();


				//get all, should automagically retrieve from each shard
				var allCompanies = session.Advanced.AsyncLuceneQuery<Company>()
					.WaitForNonStaleResults()
					.ToListAsync().Result.Item2;

				Assert.NotNull(allCompanies);
				Assert.Equal(company1.Name, allCompanies[0].Name);
				Assert.Equal(company2.Name, allCompanies[1].Name);
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:25,代码来源:WhenUsingShardedServers.cs

示例5: CanGetSingleEntityFromCorrectShardedServerWhenLocationIsUnknown

		public void CanGetSingleEntityFromCorrectShardedServerWhenLocationIsUnknown()
		{
			shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy();

			using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize())
			using (var session = documentStore.OpenAsyncSession())
			{
				//store item that goes in 2nd shard
				session.Store(company2);

				session.SaveChangesAsync().Wait();

				//get it, should try all shards and find it
				shardResolution.Stub(x => x.PotentialShardsFor(null)).IgnoreArguments().Return(null);
				var loadedCompany = session.LoadAsync<Company>(company2.Id).Result;

				Assert.NotNull(loadedCompany);
				Assert.Equal(company2.Name, loadedCompany.Name);
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:20,代码来源:WhenUsingShardedServers.cs

示例6: CanGetSingleEntityFromCorrectShardedServer

		public void CanGetSingleEntityFromCorrectShardedServer()
		{
			using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize())
			using (var session = documentStore.OpenAsyncSession())
			{
				//store item that goes in 2nd shard
				session.Store(company2);
				session.SaveChangesAsync().Wait();

				//get it, should automagically retrieve from 2nd shard
				shardResolution.Stub(x => x.PotentialShardsFor(null)).IgnoreArguments().Return(new[] { "Shard2" });
				var loadedCompany = session.LoadAsync<Company>(company2.Id).Result;

				Assert.NotNull(loadedCompany);
				Assert.Equal(company2.Name, loadedCompany.Name);
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:17,代码来源:WhenUsingShardedServers.cs

示例7: CanInsertIntoTwoShardedServers

		public void CanInsertIntoTwoShardedServers()
		{
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				using (var session = documentStore.OpenAsyncSession())
				{
					session.Store(company1);
					session.Store(company2);
					session.SaveChangesAsync().Wait();
				}
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:14,代码来源:WhenUsingShardedServers.cs

示例8: CanDisableQueryResultsCachingForAsyncShardedDocumentQuery

		public void CanDisableQueryResultsCachingForAsyncShardedDocumentQuery()
		{

			using (GetNewServer(8079))
			using (GetNewServer(8078))
			using (var store = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
			{
				{"1", CreateDocumentStore(8079)},
				{"2", CreateDocumentStore(8078)},
			})))
			{
				store.Initialize();

				using (var session = store.OpenSession())
				{
					session.Store(new Item());
					session.Store(new Item());

					session.SaveChanges();
				}

				store.ShardStrategy.Shards["1"].JsonRequestFactory.ResetCache();
				store.ShardStrategy.Shards["2"].JsonRequestFactory.ResetCache();

				using (var asyncSession = store.OpenAsyncSession())
				{
					var asyncQuery = asyncSession.Query<Item>().Customize(x => x.NoCaching().WaitForNonStaleResults()).ToListAsync();

					asyncQuery.Wait();
					Assert.Equal(2, asyncQuery.Result.Count);
				}

				Assert.Equal(0, store.ShardStrategy.Shards["1"].JsonRequestFactory.CurrentCacheSize);
				Assert.Equal(0, store.ShardStrategy.Shards["2"].JsonRequestFactory.CurrentCacheSize);
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:36,代码来源:RavenDB_790.cs

示例9: CanDisableQueryResultsTrackingForAsyncShardedDocumentQuery

		public void CanDisableQueryResultsTrackingForAsyncShardedDocumentQuery()
		{
			using (GetNewServer(8079))
			using (GetNewServer(8078))
			using (var store = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
			{
				{"1", CreateDocumentStore(8079)},
				{"2", CreateDocumentStore(8078)},
			})))
			{
				store.Initialize();

				using (var session = store.OpenSession())
				{
					session.Store(new Item());
					session.Store(new Item());

					session.SaveChanges();
				}

				using (var asyncSession = store.OpenAsyncSession())
				{
					var asyncQuery = asyncSession.Query<Item>().Customize(x => x.NoTracking().WaitForNonStaleResults()).ToListAsync();

					asyncQuery.Wait();
					Assert.Equal(2, asyncQuery.Result.Count);
					Assert.Equal(0, ((InMemoryDocumentSessionOperations)asyncSession).NumberOfEntitiesInUnitOfWork);
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:30,代码来源:RavenDB_790.cs

示例10: get_metadata_for_async_sharded

		public async Task get_metadata_for_async_sharded()
		{
			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 documentSession = shardedDocumentStore.OpenSession())
				{
					documentSession.Store(profile, profile.Id);
					documentSession.Store(profile2, profile2.Id);
					documentSession.SaveChanges();
				}

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					var metaData = documentSession.Advanced.GetMetadataFor(profile);
				}
				using (var documentSession = shardedDocumentStore.OpenAsyncSession())
				{
					//var data = await documentSession.LoadAsync<Profile>(profile.Id);
					var metaData = await documentSession.Advanced.GetMetadataForAsync(profile);
					var metaData2 = await documentSession.Advanced.GetMetadataForAsync(profile2);

					Assert.NotNull(metaData);
					Assert.NotNull(metaData2);
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:42,代码来源:RavenDB-3465.cs


注:本文中的Raven.Client.Shard.ShardedDocumentStore.OpenAsyncSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。