本文整理汇总了C#中Raven.Client.Embedded.EmbeddableDocumentStore.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# EmbeddableDocumentStore.OpenSession方法的具体用法?C# EmbeddableDocumentStore.OpenSession怎么用?C# EmbeddableDocumentStore.OpenSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Client.Embedded.EmbeddableDocumentStore
的用法示例。
在下文中一共展示了EmbeddableDocumentStore.OpenSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameConvention_ModifiedProperty
public void NameConvention_ModifiedProperty()
{
using (var store = new EmbeddableDocumentStore
{
RunInMemory = true,
Conventions =
{
FindIdentityProperty = info => info.Name == "Name"
}
}.Initialize())
{
using (var session = store.OpenSession())
{
session.Store(new Item
{
Name = "Ayende"
});
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var item = session.Load<Item>("Ayende");
item.Id = "items/2";
item.Name = "abc";
Assert.Throws<InvalidOperationException>(() => session.SaveChanges());
}
}
}
示例2: SuccessTest2
public void SuccessTest2()
{
using (IDocumentStore documentStore = new EmbeddableDocumentStore
{
RunInMemory = true
}.Initialize())
{
dynamic expando = new ExpandoObject();
using (IDocumentSession session = documentStore.OpenSession())
{
session.Store(expando);
RavenJObject metadata =
session.Advanced.GetMetadataFor((ExpandoObject)expando);
metadata[PropertyName] = RavenJToken.FromObject(true);
session.SaveChanges();
}
using (IDocumentSession session = documentStore.OpenSession())
{
dynamic loaded = session.Advanced.LuceneQuery<dynamic>()
.WhereEquals("@metadata.Raven-Entity-Name",
documentStore.Conventions.GetTypeTagName(typeof(ExpandoObject)))
.FirstOrDefault();
Assert.NotNull(loaded);
}
}
}
示例3: ReturnsBooksByPriceLimit
public void ReturnsBooksByPriceLimit()
{
using (var docStore = new EmbeddableDocumentStore { RunInMemory = true }
.Initialize()
)
{
using (var session = docStore.OpenSession())
{
// Store test data
session.Store(new Book { Title = "Test book", YearPublished = 2013, Price = 12.99 });
session.SaveChanges();
}
var controller = new BooksController { RavenSession = docStore.OpenSession() };
var viewResult = (ViewResult)controller.ListByPriceLimit(15);
var result = viewResult.ViewData.Model as List<Book>;
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count);
viewResult = (ViewResult)controller.ListByPriceLimit(10);
result = viewResult.ViewData.Model as List<Book>;
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
controller.RavenSession.Dispose();
}
}
示例4: WorkWithTransactionAndNoAllowNonAutoritiveInformation
public void WorkWithTransactionAndNoAllowNonAutoritiveInformation()
{
using (var store = new EmbeddableDocumentStore
{
RunInMemory = true
}.Initialize())
{
using (new TransactionScope())
{
using (IDocumentSession session = store.OpenSession())
{
var user = new User {Id = "users/[email protected]"};
session.Store(user);
session.SaveChanges();
}
using(new TransactionScope(TransactionScopeOption.Suppress))
using (IDocumentSession session = store.OpenSession())
{
var user = session.Load<User>("users/[email protected]");
Assert.Null(user);
}
}
}
}
示例5: CanQueryMetadata
public void CanQueryMetadata()
{
using (var store = new EmbeddableDocumentStore { RunInMemory = true })
{
store.Initialize();
using (var s = store.OpenSession())
{
s.Store(new User
{
Metadata =
{
IsActive = true
}
});
s.SaveChanges();
}
using (var s = store.OpenSession())
{
var actual = s.Query<User>()
.Customize(x=>x.WaitForNonStaleResultsAsOfLastWrite())
.Where(x => x.Metadata.IsActive == true)
.Count();
Assert.Equal(1, actual);
}
}
}
示例6: Should_retrieve_all_entities_using_connection_string
public void Should_retrieve_all_entities_using_connection_string()
{
using (var documentStore = new EmbeddableDocumentStore
{
ConnectionStringName = "Local",
Configuration =
{
RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
}
})
{
path = documentStore.DataDirectory;
documentStore.Initialize();
var session1 = documentStore.OpenSession();
session1.Store(new Company { Name = "Company 1" });
session1.Store(new Company { Name = "Company 2" });
session1.SaveChanges();
var session2 = documentStore.OpenSession();
var companyFound = session2.Advanced.DocumentQuery<Company>()
.WaitForNonStaleResults()
.ToArray();
Assert.Equal(2, companyFound.Length);
}
}
示例7: Should_give_documents_where_ExpirationDate_is_null_or_expirationdate_greater_than_today
public void Should_give_documents_where_ExpirationDate_is_null_or_expirationdate_greater_than_today()
{
using (var documentStore = new EmbeddableDocumentStore
{
RunInMemory = true,
Conventions =
{
DefaultQueryingConsistency =
ConsistencyOptions.QueryYourWrites
}
})
{
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
session.Store(new Foo());
session.Store(new Foo());
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
var bar =
session.Query<Foo>()
.Where(foo => foo.ExpirationTime == null || foo.ExpirationTime > DateTime.Now)
.ToList();
Assert.That(bar.Count, Is.EqualTo(2));
}
}
}
示例8: SuccessTest1
public void SuccessTest1()
{
using (IDocumentStore documentStore = new EmbeddableDocumentStore
{
RunInMemory = true
}.Initialize())
{
dynamic expando = new ExpandoObject();
using (IDocumentSession session = documentStore.OpenSession())
{
session.Store(expando);
RavenJObject metadata =
session.Advanced.GetMetadataFor((ExpandoObject)expando);
metadata[PropertyName] = RavenJToken.FromObject(true);
session.SaveChanges();
}
using (IDocumentSession session = documentStore.OpenSession())
{
var loaded =
session.Load<dynamic>((string)expando.Id);
RavenJObject metadata =
session.Advanced.GetMetadataFor((DynamicJsonObject)loaded);
RavenJToken token = metadata[PropertyName];
Assert.NotNull(token);
Assert.True(token.Value<bool>());
}
}
}
示例9: DoTest
private static void DoTest(DateTime dt, DateTimeKind inKind, DateTimeKind outKind)
{
Assert.Equal(inKind, dt.Kind);
using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true })
{
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
session.Store(new Foo { Id = "foos/1", DateTime = dt });
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
var foo = session.Query<Foo>()
.Customize(x => x.WaitForNonStaleResults())
.FirstOrDefault(x => x.DateTime == dt);
WaitForUserToContinueTheTest(documentStore);
Assert.Equal(dt, foo.DateTime);
Assert.Equal(outKind, foo.DateTime.Kind);
}
}
}
示例10: Test_paralel_operations_with_multiple_EmbeddableDocumentStores
public void Test_paralel_operations_with_multiple_EmbeddableDocumentStores()
{
Action storeAndRead = () =>
{
using (var store = new EmbeddableDocumentStore
{
RunInMemory = true
})
{
store.Initialize();
using (var session = store.OpenSession())
{
session.Store(new Document { Value = "foo" }, "documents/1");
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var doc = session.Load<Document>("documents/1");
Assert.Equal("foo", doc.Value);
}
}
};
storeAndRead();
var tasks = Enumerable.Range(1, 10).Select(_ => Task.Run(storeAndRead)).ToArray();
Task.WaitAll(tasks);
}
示例11: ShouldWork
public void ShouldWork()
{
using (var _documentStore = new EmbeddableDocumentStore
{
RunInMemory = true,
Conventions =
{
DefaultQueryingConsistency =
ConsistencyOptions.QueryYourWrites
}
})
{
_documentStore.Initialize();
using (var session = _documentStore.OpenSession())
{
session.Store(new Foo());
session.Store(new Foo());
session.SaveChanges();
}
using (var session = _documentStore.OpenSession())
{
var bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null || foo.ExpirationTime > DateTime.Now).ToList();
Assert.Equal(2, bar.Count);
}
}
}
示例12: StandaloneTestForPostingOnStackOverflow
public void StandaloneTestForPostingOnStackOverflow()
{
var testDocument = new Cart { Email = "[email protected]" };
using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true })
{
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
using (var transaction = new TransactionScope())
{
session.Store(testDocument);
session.SaveChanges();
transaction.Complete();
}
}
using (var session = documentStore.OpenSession())
{
using (var transaction = new TransactionScope())
{
var documentToDelete = session
.Query<Cart>()
.Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
.First(c => c.Email == testDocument.Email);
session.Delete(documentToDelete);
session.SaveChanges();
transaction.Complete();
}
}
using (var session = documentStore.OpenSession())
{
session.Advanced.AllowNonAuthoritativeInformation = false;
RavenQueryStatistics statistics;
Assert.Null(session
.Query<Cart>()
.Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
.FirstOrDefault(c => c.Email == testDocument.Email));
// we force a wait here, because there is no way to wait for NonAuthoritativeInformation on a count
var actualCount = session
.Query<Cart>()
.Statistics(out statistics)
.Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
.Count(c => c.Email == testDocument.Email);
Assert.False(statistics.IsStale);
Assert.False(statistics.NonAuthoritativeInformation);
Assert.Equal(0, actualCount);
}
}
}
示例13: can_index_on_a_reference2
public void can_index_on_a_reference2()
{
using (var store = new EmbeddableDocumentStore
{
RunInMemory = true
})
{
store.Initialize();
using (var session = store.OpenSession())
{
var category = new Category()
{
Name = "Parent"
};
category.Add(new Category()
{
Name = "Child"
});
session.Store(category);
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var results0 = session.Query<Category>()
.Customize(x=>x.WaitForNonStaleResults(TimeSpan.FromHours(1)))
.ToList();
Assert.Equal(1, results0.Count);
// WORKS
var results1 = session.Query<Category>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => x.Children.Any(y => y.Name == "Child")).
ToList();
Assert.Equal(1, results1.Count);
// FAILS
var results2 = session.Query<Category>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => x.Children.Any(y => y.Parent.Name == "Parent"))
.ToList();
Assert.Equal(1, results2.Count);
}
}
}
示例14: ShouldOnlyBeInDataDir
public void ShouldOnlyBeInDataDir()
{
IOExtensions.DeleteDirectory("App_Data");
IOExtensions.DeleteDirectory("Data");
Assert.False(Directory.Exists("App_Data"));
Assert.False(Directory.Exists("Data"));
using (var store = new EmbeddableDocumentStore {DataDirectory = "App_Data"}.Initialize())
{
using (var session = store.OpenSession())
{
string someEmail = "[email protected]";
session.Query<User>().Where(u => u.Email == someEmail).FirstOrDefault();
session.Store(new User {Email = "[email protected]"});
session.SaveChanges();
session.Query<User>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.Where(u => u.Email == someEmail)
.Single();
}
}
Assert.True(Directory.Exists("App_Data"));
Assert.False(Directory.Exists("Data"));
IOExtensions.DeleteDirectory("App_Data");
IOExtensions.DeleteDirectory("Data");
}
示例15: ScriptHelper
public ScriptHelper()
{
var p1 = Path.Combine("Data", "System.db");
SystemStore = new EmbeddableDocumentStore { DataDirectory = p1 };
SystemStore.Initialize();
System = SystemStore.OpenSession();
SystemStore.Conventions.RegisterIdConvention<DbSetting>((db, cmds, setting) => "Settings/" + setting.Name);
SystemStore.Conventions.RegisterIdConvention<DbScript>((db, cmds, script) => "Scripts/" + script.Name);
try
{
SystemStore.DatabaseCommands.PutIndex("Settings/ByName", new IndexDefinitionBuilder<DbSetting>
{
Map = settings =>
from setting
in settings
select new { setting.Name }
});
SystemStore.DatabaseCommands.PutIndex("Scripts/ByName", new IndexDefinitionBuilder<DbScript>
{
Map = scripts =>
from script
in scripts
select new { script.Name }
});
}
catch (Exception)
{
}
IndexCreation.CreateIndexes(typeof(DbScript).Assembly,SystemStore);
IndexCreation.CreateIndexes(typeof(DbSetting).Assembly, SystemStore);
}