本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例7: InitializeSession
void InitializeSession()
{
var store = new DocumentStore { Url = Address };
store.Initialize();
Session = store.OpenAsyncSession();
}
示例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);
}
}
示例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);
}
}
示例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"));
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}