本文整理汇总了C#中Raven.Client.Document.DocumentStore.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentStore.OpenSession方法的具体用法?C# DocumentStore.OpenSession怎么用?C# DocumentStore.OpenSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Client.Document.DocumentStore
的用法示例。
在下文中一共展示了DocumentStore.OpenSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanProfileLazyRequests
public void CanProfileLazyRequests()
{
using (GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8079" })
{
store.Initialize();
store.InitializeProfiling();
using (var session = store.OpenSession())
{
// handle the initial request for replication information
}
Guid id;
using (var session = store.OpenSession())
{
id = ((DocumentSession)session).DatabaseCommands.ProfilingInformation.Id;
session.Advanced.Lazily.Load<User>("users/1");
session.Advanced.Lazily.Load<User>("users/2");
session.Advanced.Lazily.Load<User>("users/3");
session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();
}
var profilingInformation = store.GetProfilingInformationFor(id);
Assert.Equal(1, profilingInformation.Requests.Count);
var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result, Default.Converters);
Assert.Equal(3, responses.Length);
foreach (var response in responses)
{
Assert.Equal(404, response.Status);
}
}
}
示例2: CanTrackPosts
public void CanTrackPosts()
{
using (GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8080" })
{
store.Initialize();
// make the replication check here
using (var session = store.OpenSession())
{
session.Load<User>("users/1");
}
Guid id;
using (var session = store.OpenSession())
{
session.Store(new User());
session.SaveChanges();
id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
}
var profilingInformation = store.GetProfilingInformationFor(id);
Assert.Equal(1, profilingInformation.Requests.Count);
}
}
示例3: CanGenerateComplexPaths
public void CanGenerateComplexPaths()
{
using (GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
{
using (var s = store.OpenSession())
{
s.Store(new User { Name = "Ayende" });
s.Store(new User
{
Name = "Rahien",
Friends = new[]
{
new DenormalizedReference {Name = "Ayende", Id = "users/1"},
}
});
s.SaveChanges();
}
using (var s = store.OpenSession())
{
var user = s.Include("Friends,Id").Load<User>("users/2");
Assert.Equal(1, user.Friends.Length);
foreach (var denormalizedReference in user.Friends)
{
s.Load<User>(denormalizedReference.Id);
}
Assert.Equal(1, s.Advanced.NumberOfRequests);
}
}
}
示例4: CanQueryDefaultDatabaseQuickly
public void CanQueryDefaultDatabaseQuickly()
{
using (GetNewServer(8080))
using (var store = new DocumentStore
{
Url = "http://localhost:8080"
}.Initialize())
{
store.DatabaseCommands.EnsureDatabaseExists("Northwind");
using (var s = store.OpenSession("Northwind"))
{
var entity = new User
{
Name = "Hello",
};
s.Store(entity);
s.SaveChanges();
}
var sp = Stopwatch.StartNew();
using (var s = store.OpenSession())
{
Assert.Empty(s.Query<User>().Where(x => x.Name == "Hello"));
}
Assert.True(TimeSpan.FromSeconds(5) > sp.Elapsed);
}
}
示例5: After_modification_will_get_value_from_server
public void After_modification_will_get_value_from_server()
{
using (GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8080" }.Initialize())
{
using (var s = store.OpenSession())
{
s.Store(new User { Name = "Ayende" });
s.SaveChanges();
}
using (var s = store.OpenSession())
{
s.Load<User>("users/1");
s.SaveChanges();
}
using (var s = store.OpenSession())
{
var user = s.Load<User>("users/1");
user.Name = "Rahien";
Assert.Equal(1, HttpJsonRequest.NumberOfCachedRequests);
s.SaveChanges();
}
using (var s = store.OpenSession())
{
s.Load<User>("users/1");
Assert.Equal(1, HttpJsonRequest.NumberOfCachedRequests); // did NOT get from cache
}
}
}
示例6: Can_read_entity_name_after_update_from_query_after_entity_is_in_cache
public void Can_read_entity_name_after_update_from_query_after_entity_is_in_cache()
{
using (GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8080" }.Initialize())
{
using (var s = store.OpenSession())
{
s.Store(new Event { Happy = true });
s.SaveChanges();
}
using (var s = store.OpenSession())
{
s.Load<Event>("events/1");//load into cache
}
using (var s = store.OpenSession())
{
s.Load<Event>("events/1").Happy = false;
s.SaveChanges();
}
using (var s = store.OpenSession())
{
var events = s.Query<Event>().Customize(x => x.WaitForNonStaleResults()).ToArray();
Assert.NotEmpty(events);
}
}
}
示例7: Main
static void Main(string[] args)
{
var documentStore1 = new DocumentStore { Url = "http://localhost:8080" }.Initialize();
using (var session1 = documentStore1.OpenSession())
{
session1.Store(new User { Id = "users/ayende", Name = "Ayende" });
session1.SaveChanges();
}
using (var session1 = documentStore1.OpenSession())
{
Console.WriteLine(session1.Load<User>("users/ayende").Name);
}
Console.WriteLine("Wrote one docuemnt to 8080, ready for server failure");
Console.ReadLine();
using (var session1 = documentStore1.OpenSession())
{
Console.WriteLine(session1.Load<User>("users/ayende").Name);
}
}
示例8: CanUseInclude_Remote
public void CanUseInclude_Remote()
{
using (GetNewServer())
using (var store = new DocumentStore
{
Url = "http://localhost:8079"
}.Initialize())
{
using (var s = store.OpenSession())
{
var user = new User { FirstName = "Demo", LastName = "User" };
s.Store(user);
var item = new Item(user.Id, "Stuff");
s.Store(item);
user.UserItems = new List<UserItem>
{
new UserItem
{
Item = new ItemReference {Id = item.Id, Summary = item.Summary, UserId = item.UserId},
Name = "Stuff 2"
}
};
s.SaveChanges();
}
using (var s = store.OpenSession())
{
var userLookup = s.Include<UserItem>(x => x.Item.Id).Load<User>(1);
foreach (var uit in userLookup.UserItems)
{
var item2 = s.Load<Item>(uit.Item.Id);
}
}
}
}
示例9: Can_cache_document_with_includes
public void Can_cache_document_with_includes()
{
using (GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
{
using (var s = store.OpenSession())
{
s.Store(new User {Name = "Ayende"});
s.Store(new User { PartnerId = "users/1"});
s.SaveChanges();
}
using (var s = store.OpenSession())
{
s.Include<User>(x=>x.PartnerId)
.Load("users/2");
s.SaveChanges();
}
using (var s = store.OpenSession())
{
s.Include<User>(x => x.PartnerId)
.Load("users/2");
Assert.Equal(1, store.JsonRequestFactory.NumberOfCachedRequests);
}
}
}
示例10: Main
static void Main()
{
using (var store = new DocumentStore
{
Url = "https://2.ravenhq.com/databases/ayende-freedb",
ApiKey = "2cdd2658-1181-4d67-b15e-7adcc48c461a"
}.Initialize())
{
var session = store.OpenSession();
var count = 0;
var sp = ParseDisks(diskToAdd =>
{
session.Store(diskToAdd);
count += 1;
if (count < BatchSize)
return;
session.SaveChanges();
session = store.OpenSession();
count = 0;
});
session.SaveChanges();
Console.WriteLine();
Console.WriteLine("Done in {0}", sp.Elapsed);
}
}
示例11: CanUseMultiGetToBatchGetDocumentRequests
public void CanUseMultiGetToBatchGetDocumentRequests()
{
using (GetNewServer())
using (var docStore = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
{
for (int i = 0; i < 10; i++)
{
string id;
using (var tx = new TransactionScope())
using (var session = docStore.OpenSession())
{
Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
new ManyDocumentsViaDTC.DummyEnlistmentNotification(), EnlistmentOptions.None);
var entity = new User { Name = "Ayende" };
session.Store(entity);
session.SaveChanges();
id = entity.Id;
tx.Complete();
}
using (var session = docStore.OpenSession())
{
session.Advanced.AllowNonAuthoritativeInformation = false;
var user = session.Advanced.Lazily.Load<User>(id);
Assert.NotNull(user.Value);
}
}
}
}
示例12: MultiMapIndexes
public void MultiMapIndexes()
{
using (var store = new DocumentStore())
{
using (var session = store.OpenSession())
{
#region multi_map_2
List<object> results = session
.Advanced
.DocumentQuery<object, Animals_ByName>()
.WhereEquals("Name", "Mitzy")
.ToList();
#endregion
}
using (var session = store.OpenSession())
{
#region multi_map_3
IList<IAnimal> results = session
.Query<IAnimal, Animals_ByName>()
.Where(x => x.Name == "Mitzy")
.ToList();
#endregion
}
}
}
示例13: query_for_object_with_byte_array_with_default_TypeNameHandling
public void query_for_object_with_byte_array_with_default_TypeNameHandling()
{
using (var server = GetNewServer())
using (var store = new DocumentStore { Url = "http://localhost:8079" })
{
store.Initialize();
var json = GetResourceText("DocumentWithBytes.txt");
var jsonSerializer = new DocumentConvention().CreateSerializer();
var item = jsonSerializer.Deserialize<DesignResources>(new JsonTextReader(new StringReader(json)));
using (var session = store.OpenSession())
{
item.Id = "resources/123";
item.DesignId = "designs/123";
session.Store(item);
session.SaveChanges();
}
using (var session = store.OpenSession())
{
session
.Query<DesignResources>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.Where(x => x.DesignId == "designs/123")
.ToList();
}
}
}
示例14: 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
}
}
示例15: CanAccessDbUsingDifferentNames
public void CanAccessDbUsingDifferentNames()
{
using (GetNewServer())
{
using (var documentStore = new DocumentStore
{
Url = "http://localhost:8080"
})
{
documentStore.Initialize();
documentStore.DatabaseCommands.EnsureDatabaseExists("repro");
using (var session = documentStore.OpenSession("repro"))
{
session.Store(new Foo
{
Bar = "test"
});
session.SaveChanges();
}
using (var session = documentStore.OpenSession("Repro"))
{
Assert.NotNull(session.Load<Foo>("foos/1"));
}
}
}
}