本文整理汇总了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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
}
示例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
}
}
}
示例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
}
}
示例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);
}
}
}
示例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);
}
}
}
}
}
示例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);
}
}
}
示例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"));
}
}
}
}
示例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"));
}
}
}
}