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


C# DocumentStore.OpenAsyncSession方法代码示例

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


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

示例1: Including_a_related_entity_should_avoid_hitting_the_server_twice

		public IEnumerable<Task> Including_a_related_entity_should_avoid_hitting_the_server_twice()
		{
			var dbname = GenerateNewDatabaseName();
			var documentStore = new DocumentStore { Url = Url + Port };
			documentStore.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")
					.QueryResultAsync;
				yield return query;

				Assert.Equal("Hello", query.Result.Results[0].Value<string>("Note"));

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

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

示例2: Can_get_total_count

		public IEnumerable<Task> Can_get_total_count()
		{
			var dbname = GenerateNewDatabaseName();
			var documentStore = new DocumentStore { Url = Url + Port };
			documentStore.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:runesoerensen,项目名称:ravendb,代码行数:27,代码来源:AsyncLinqQueryTests.cs

示例3: Can_perform_a_simple_where

		public IEnumerable<Task> Can_perform_a_simple_where()
		{
			var dbname = GenerateNewDatabaseName();
			var documentStore = new DocumentStore { Url = Url + Port };
			documentStore.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:philiphoy,项目名称:ravendb,代码行数:25,代码来源:AsyncLinqQueryTests.cs

示例4: Can_insert_async_and_multi_get_async

        public IEnumerable<Task> Can_insert_async_and_multi_get_async()
        {
            var dbname = GenerateNewDatabaseName();
            var documentStore = new DocumentStore {Url = Url + Port};
            documentStore.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.MultiLoadAsync<Company>(new[] {entity1.Id, entity2.Id});
                yield return task;

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

示例5: Can_test_two_conditions_in_a_where_clause

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

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

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

				Assert.AreEqual(1, query.Result.Count);
				Assert.AreEqual(12345, query.Result[0].Phone);
			}
		}
开发者ID:philiphoy,项目名称:ravendb,代码行数:25,代码来源:AsyncLinqQueryTests.cs

示例6: Some_sample_data

		public IEnumerable<Task> Some_sample_data()
		{
			var store = new DocumentStore {Url = Url + Port};
			store.Initialize();

			using (var session = store.OpenAsyncSession())
			{
				Enumerable.Range(0, 25).ToList()
					.ForEach(i => session.Store(new Company {Id = "Companies/" + i, Name = i.ToString()}));

				Enumerable.Range(0, 250).ToList()
					.ForEach(i => session.Store(new Order { Id = "Orders/" + i, Note = i.ToString() }));

				Enumerable.Range(0, 100).ToList()
					.ForEach(i => session.Store(new Customer { Name = "Joe " + i}));

				Enumerable.Range(0, 75).ToList()
					.ForEach(i => session.Store(new Contact { FirstName = "Bob" + i, Surname = i.ToString() + "0101001" }));

				session.Store(new Customer { Name = "Henry"});
				session.Store(new Order { Note = "An order" });
				session.Store(new Company {Name = "My Company"});

				yield return session.SaveChangesAsync();
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:26,代码来源:Generate.cs

示例7: InitializeSession

		void InitializeSession()
		{
			var store = new DocumentStore { Url = Address };

			store.Initialize();

			Session = store.OpenAsyncSession();
		}
开发者ID:jaircazarin,项目名称:ravendb,代码行数:8,代码来源:Database.cs

示例8: Can_insert_async_and_load_async

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

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

			using (var session_for_loading = documentStore.OpenAsyncSession(dbname))
			{
				var task = session_for_loading.LoadAsync<Company>(entity.Id);
				yield return task;

				Assert.AreEqual(entity.Name, task.Result.Name);
			}
		}
开发者ID:philiphoy,项目名称:ravendb,代码行数:22,代码来源:AsyncDocumentStoreServerTests.cs

示例9: Can_insert_async_and_delete_async

        public IEnumerable<Task> Can_insert_async_and_delete_async()
        {
            var dbname = GenerateNewDatabaseName();
            var documentStore = new DocumentStore {Url = Url + Port};
            documentStore.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 for_loading = documentStore.OpenAsyncSession(dbname))
            {
                var loading = for_loading.LoadAsync<Company>(entity.Id);
                yield return loading;
                Assert.NotNull(loading.Result);
            }

            using (var for_deleting = documentStore.OpenAsyncSession(dbname))
            {
                var loading = for_deleting.LoadAsync<Company>(entity.Id);
                yield return loading;

                for_deleting.Delete(loading.Result);
                yield return for_deleting.SaveChangesAsync();
            }

            using (var for_verifying = documentStore.OpenAsyncSession(dbname))
            {
                var verification = for_verifying.LoadAsync<Company>(entity.Id);
                yield return verification;

                Assert.Null(verification.Result);
            }
        }
开发者ID:aduggleby,项目名称:ravendb,代码行数:38,代码来源:AsyncDocumentStoreServerTests.cs

示例10: Can_query_using_async_session

		public IEnumerable<Task> Can_query_using_async_session()
		{
			var dbname = GenerateNewDatabaseName();
			var documentStore = new DocumentStore {Url = Url + Port};
			documentStore.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")
					.QueryResultAsync;

				yield return queryResultAsync;

				Assert.Equal("Ayende", queryResultAsync.Result.Results[0].Value<string>("Name"));
			}
		}
开发者ID:aduggleby,项目名称:ravendb,代码行数:24,代码来源:AsyncLuceneQueryTests.cs

示例11: Can_query_on_not_equal

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

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

			using (var s = documentStore.OpenAsyncSession(dbname))
			{
				var query = s.Query<Company>()
					.Where(x => x.Name != "Oren")
					.ToListAsync();
				yield return query;

				Assert.Equal(1, query.Result.Count);
			}
		}
开发者ID:aduggleby,项目名称:ravendb,代码行数:24,代码来源:AsyncLinqQueryTests.cs

示例12: Calling_ToList_raises_an_exception

		//[ExpectedException(typeof(NotSupportedException))]
		public IEnumerable<Task> Calling_ToList_raises_an_exception()
		{
			var dbname = GenerateNewDatabaseName();
			var documentStore = new DocumentStore { Url = Url + Port };
			documentStore.Initialize();
			yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

			using (var session = documentStore.OpenAsyncSession(dbname))
			{
				//NOTE: shouldn't compile
				//var query = session.Query<Company>()
				//            .Where(x => x.Name == "Doesn't Really Matter")
				//            .ToList();

				// should compile
				var list = new List<string>().ToList();
			}
		}
开发者ID:philiphoy,项目名称:ravendb,代码行数:19,代码来源:AsyncLinqQueryTests.cs

示例13: Can_get_collections_async

		//NOTE: This expects a certain index to be present that is currently only created when Studio accesses a database 
		public IEnumerable<Task> Can_get_collections_async()
		{
			var dbname = GenerateNewDatabaseName();
			var store = new DocumentStore {Url = Url + Port};
			store.Initialize();


			yield return store.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

			yield return
				IndexCreation.CreateIndexesAsync(new CompositionContainer(new TypeCatalog(typeof (RavenCollections))),
				                                 store.AsyncDatabaseCommands.ForDatabase(dbname), store.Conventions);

			using (var session = store.OpenAsyncSession(dbname))
			{
				Enumerable.Range(0, 25).ToList()
					.ForEach(i => session.Store(new Company {Id = "Companies/" + i, Name = i.ToString()}));

				Enumerable.Range(0, 25).ToList()
					.ForEach(i => session.Store(new Order {Id = "Orders/" + i, Note = i.ToString()}));

				yield return session.SaveChangesAsync();
			}

			
			Task<Collection[]> task;
			do
			{
				task = store.AsyncDatabaseCommands.ForDatabase(dbname)
					.GetCollectionsAsync(0, 25);
				yield return task;
				if (task.Result.Length == 0)
					yield return Delay(100);
			} while (task.Result.Length == 0); 

			var collections = task.Result;

			Assert.AreEqual("Companies", collections[0].Name);
			Assert.AreEqual("Orders", collections[1].Name);
			Assert.AreEqual(25, collections[0].Count);
			Assert.AreEqual(25, collections[1].Count);
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:43,代码来源:Collections.cs

示例14: Can_get_documents_async

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

			using (var session = store.OpenAsyncSession(dbname))
			{
				session.Store(new Company { Name = "Hai" });
				session.Store(new Company { Name = "I can haz cheezburgr?" });
				session.Store(new Company { Name = "lol" });
				yield return session.SaveChangesAsync();
			}

			var task = cmd.ForDatabase(dbname).GetDocumentsAsync(0, 25);
			yield return task;

			Assert.AreEqual(3, task.Result.Length);
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:21,代码来源:AsyncDatabaseCommandsTests.cs

示例15: Can_get_documents_whose_id_starts_with_a_prefix

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

			using (var session = store.OpenAsyncSession(dbname))
			{
				session.Store(new Company { Name = "Something with the desired prefix" });
				session.Store(new Contact { Surname = "Something without the desired prefix" });
				yield return session.SaveChangesAsync();
			}

			var task = cmd
				.ForDatabase(dbname)
				.GetDocumentsStartingWithAsync("Companies", 0, 25);
			yield return task;

			Assert.AreEqual(1, task.Result.Length);
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:22,代码来源:AsyncDatabaseCommandsTests.cs


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