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


C# DocumentStore.OpenAsyncSession方法代码示例

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


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

示例1: AsyncLoad

		public void AsyncLoad()
		{
			using (GetNewServer())
			using (var store = new DocumentStore
			{
				Url = "http://localhost:8079"
			}.Initialize())
			{
				using (var session = store.OpenAsyncSession())
				{
					session.Store(new Dummy() );

					session.SaveChangesAsync().Wait();
				}
				using (var session = store.OpenAsyncSession())
				{
					session.LoadAsync<Dummy>("dummies/1").Wait();
					Assert.Equal(0, store.JsonRequestFactory.NumberOfCachedRequests);
				}
				using (var session = store.OpenAsyncSession())
				{
					session.LoadAsync<Dummy>("dummies/1").Wait();
					Assert.Equal(1, store.JsonRequestFactory.NumberOfCachedRequests);
				}
			}
		}
开发者ID:neiz,项目名称:ravendb,代码行数:26,代码来源:RavenAsyncTest.cs

示例2: CanPerformASimpleWhere

		public IEnumerable<Task> CanPerformASimpleWhere()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					session.Store(entity);
					yield return session.SaveChangesAsync();
				}

				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					var query = session.Query<Company>()
						.Where(x => x.Name == "Async Company #1")
						.ToListAsync();
					yield return query;

					Assert.AreEqual(1, query.Result.Count);
					Assert.AreEqual("Async Company #1", query.Result[0].Name);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:26,代码来源:AsyncLinqQueryTests.cs

示例3: IncludingARelatedEntityShouldAvoidHittingTheServerTwice

		public IEnumerable<Task> IncludingARelatedEntityShouldAvoidHittingTheServerTwice()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var customer = new Customer {Name = "Customer #1", Id = "customer/1", Email = "[email protected]"};
				var order = new Order {Id = "orders/1", Note = "Hello", Customer = new DenormalizedReference {Id = customer.Id, Name = customer.Name}};
				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					session.Store(customer);
					session.Store(order);
					yield return session.SaveChangesAsync();
				}

				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					var query = session.Advanced.AsyncLuceneQuery<Order>()
						.Include(x => x.Customer.Id)
						.WhereEquals("Id", "orders/1")
						.ToListAsync();
					yield return query;

					Assert.AreEqual("Hello", query.Result.Item2[0].Note);

					// NOTE: this call should not hit the server 
					var load = session.LoadAsync<Customer>(customer.Id);
					yield return load;

					Assert.AreEqual(1, session.Advanced.NumberOfRequests);
				}
			}
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:34,代码来源:AsyncLuceneQueryTests.cs

示例4: CanGetTotalCount

		public IEnumerable<Task> CanGetTotalCount()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					session.Store(entity);
					yield return session.SaveChangesAsync();
				}

				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					RavenQueryStatistics stats;
					var query = session.Query<Company>()
						.Customize(x => x.WaitForNonStaleResults())
						.Statistics(out stats)
						.Where(x => x.Name == "Async Company #1")
						.CountAsync();
					yield return query;

					Assert.AreEqual(1, query.Result);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:28,代码来源:AsyncLinqQueryTests.cs

示例5: Can_query_using_async_session

        public void Can_query_using_async_session()
        {
            using(GetNewServer())
            using(var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                using (var s = store.OpenAsyncSession())
                {
                    s.Store(new {Name = "Ayende"});
                    s.SaveChangesAsync().Wait();
                }

                using(var s = store.OpenAsyncSession())
                {
                    var queryResultAsync = s.Advanced.AsyncLuceneQuery<dynamic>()
                        .WhereEquals("Name", "Ayende")
                        .ToListAsync();

                    queryResultAsync.Wait();

                    Assert.Equal("Ayende",
                        queryResultAsync.Result[0].Name);
                }
            }
        }
开发者ID:kblooie,项目名称:ravendb,代码行数:27,代码来源:Querying.cs

示例6: CanInsertAsyncAndMultiGetAsync

		public IEnumerable<Task> CanInsertAsyncAndMultiGetAsync()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity1 = new Company {Name = "Async Company #1"};
				var entity2 = new Company {Name = "Async Company #2"};
				using (var session_for_storing = documentStore.OpenAsyncSession(dbname))
				{
					session_for_storing.Store(entity1);
					session_for_storing.Store(entity2);
					yield return session_for_storing.SaveChangesAsync();
				}

				using (var session_for_loading = documentStore.OpenAsyncSession(dbname))
				{
					var task = session_for_loading.LoadAsync<Company>(new[] {entity1.Id, entity2.Id});
					yield return task;

					Assert.AreEqual(entity1.Name, task.Result[0].Name);
					Assert.AreEqual(entity2.Name, task.Result[1].Name);
				}
			}
		}
开发者ID:jtmueller,项目名称:ravendb,代码行数:26,代码来源:AsyncDocumentStoreServerTests.cs

示例7: CanQueryUsingAsyncSession

		public IEnumerable<Task> CanQueryUsingAsyncSession()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				using (var s = documentStore.OpenAsyncSession(dbname))
				{
					s.Store(new User {Name = "Ayende"});
					yield return s.SaveChangesAsync();
				}

				using (var s = documentStore.OpenAsyncSession(dbname))
				{
					var queryResultAsync = s.Advanced.AsyncLuceneQuery<User>()
						.WhereEquals("Name", "Ayende")
						.ToListAsync();

					yield return queryResultAsync;

					Assert.AreEqual("Ayende", queryResultAsync.Result.Item2[0].Name);
				}
			}
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:25,代码来源:AsyncLuceneQueryTests.cs

示例8: InitializeDocumentsCursor

        private async Task InitializeDocumentsCursor(CancellationToken cancellation)
        {
            using (var store = new DocumentStore())
            {
                store.ParseConnectionString(configuration.ConnectionString);
                store.Initialize(false);

                using (var session = store.OpenAsyncSession())
                {
                    if (String.IsNullOrEmpty(configuration.Query))
                    {
                        documentsCursor = await session.Advanced.StreamAsync<RavenJObject>(Etag.Empty, 0, int.MaxValue, null, cancellation);
                    }
                    else
                    {
                        var query = String.IsNullOrEmpty(configuration.Index)
                            ? session.Advanced.AsyncDocumentQuery<RavenJObject>()
                            : session.Advanced.AsyncDocumentQuery<RavenJObject>(configuration.Index);

                        // Streaming query API does not create a dynamic index, so user have to specify one if query is provided: http://issues.hibernatingrhinos.com/issue/RavenDB-1410
                        documentsCursor = await session.Advanced.StreamAsync<RavenJObject>(
                            query.Where(configuration.Query).NoCaching().NoTracking(), cancellation);
                    }
                }
            }
        }
开发者ID:kingkino,项目名称:azure-documentdb-datamigrationtool,代码行数:26,代码来源:RavenDbSourceAdapter.cs

示例9: Sample

		public async Task Sample()
		{
			using (var store = new DocumentStore())
			{
				var user = new RavenJObject
					{
						{"Name", "John"}
					};

				using (var session = store.OpenAsyncSession())
				{
					#region write_assurance_1
					await session.StoreAsync(user);
					await session.SaveChangesAsync();

					Etag userEtag = session
						.Advanced
						.GetEtagFor(user);

					int replicas = await store
						.Replication
						.WaitAsync(etag: userEtag, timeout: TimeSpan.FromMinutes(1), replicas: 1);
					#endregion

					#region write_assurance_2
					await store
						.Replication
						.WaitAsync();
					#endregion
				}
			}
		}
开发者ID:modulexcite,项目名称:docs-8,代码行数:32,代码来源:WriteAssurance.cs

示例10: OpeningSession

		public OpeningSession()
		{
			string databaseName = "DB1";

			using (var store = new DocumentStore())
			{
				#region open_session_2
				store.OpenSession(new OpenSessionOptions());
				#endregion

				#region open_session_3
				store.OpenSession(new OpenSessionOptions
									  {
										  Database = databaseName
									  });
				#endregion

				#region open_session_4
				using (IDocumentSession session = store.OpenSession())
				{
					// code here
				}
				#endregion

				#region open_session_5
				using (IAsyncDocumentSession session = store.OpenAsyncSession())
				{
					// async code here
				}
				#endregion
			}
		}
开发者ID:modulexcite,项目名称:docs-8,代码行数:32,代码来源:OpeningSession.cs

示例11: Can_insert_sync_and_get_async

		public void Can_insert_sync_and_get_async()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialize();

				var entity = new Company { Name = "Async Company" };
				using (var session = documentStore.OpenSession())
				{
					session.Store(entity);
					session.SaveChanges();
				}

				using (var session = documentStore.OpenAsyncSession())
				{
					var asyncResult = session.BeginLoad(entity.Id, null, null);
					if (asyncResult.CompletedSynchronously == false)
						asyncResult.AsyncWaitHandle.WaitOne();

					var company = session.EndLoad<Company>(asyncResult);
					Assert.Equal("Async Company", company.Name);
				}
			}
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:25,代码来源:AsyncDocumentStoreServerTests.cs

示例12: WillResultInTheSameResults_Lucene_Async

		public void WillResultInTheSameResults_Lucene_Async()
		{
			using (GetNewServer())
			using (var store = new DocumentStore
			{
				Url = "http://localhost:8079"
			}.Initialize())
			{
				using (var s = store.OpenSession())
				{
					s.Store(new User());
					s.Store(new User());
					s.SaveChanges();
				}

				using (var s = store.OpenAsyncSession())
				{
					var query = s.Advanced.AsyncLuceneQuery<User>();

					for (int i = 0; i < 5; i++)
					{
						var listAsync = query.ToListAsync();
						listAsync.Wait();
						foreach (var user in listAsync.Result.Item2)
						{
							Assert.NotNull(user.Id);
						}
					}
				}
			}
		}
开发者ID:jtmueller,项目名称:ravendb,代码行数:31,代码来源:IteratingTwice.cs

示例13: CanSaveAndLoad

		public async Task CanSaveAndLoad()
		{
			using (var store = new DocumentStore {Url = Url}.Initialize())
			{
				using (var session = store.OpenAsyncSession())
				{
					await session.StoreAsync(new User { Name = "Fitzchak" });
					await session.SaveChangesAsync();
				}

				using (var session = store.OpenAsyncSession())
				{
					var user = await session.LoadAsync<User>("users/1");
					Assert.NotNull(user);
					Assert.Equal("Fitzchak", user.Name);
				}
			}
		}
开发者ID:randacc,项目名称:ravendb,代码行数:18,代码来源:BasicSessionApiTests.cs

示例14: CanStartWithoutServerAsync

        public async Task CanStartWithoutServerAsync()
        {
            using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
            {
                using (var session = store.OpenAsyncSession())
                {
                    await AssertAsync.Throws<HttpRequestException>(async () => await session.LoadAsync<User>("user/1"));
                }

                using (GetNewServer())
                {
                    using (var session = store.OpenAsyncSession())
                    {
                        Assert.Null(await session.LoadAsync<Item>("items/1"));
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:18,代码来源:WillNotFailSystemIfServerIsNotAvailableOnStartup.cs

示例15: CanStartWithoutServerAsync

		public async Task CanStartWithoutServerAsync()
		{
			using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
			{
				using (var session = store.OpenAsyncSession())
				{
					var aggregateException = await AssertAsync.Throws<AggregateException>(async () => await session.LoadAsync<User>("user/1"));
					Assert.IsType<WebException>(aggregateException.Flatten().InnerException);
				}

				using (GetNewServer())
				{
					using (var session = store.OpenAsyncSession())
					{
						Assert.Null(await session.LoadAsync<Item>("items/1"));
					}
				}
			}
		}
开发者ID:robashton,项目名称:ravendb,代码行数:19,代码来源:WillNotFailSystemIfServerIsNotAvailableOnStartup.cs


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