本文整理汇总了C#中DocumentStore类的典型用法代码示例。如果您正苦于以下问题:C# DocumentStore类的具体用法?C# DocumentStore怎么用?C# DocumentStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentStore类属于命名空间,在下文中一共展示了DocumentStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例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: 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);
}
}
示例4: 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);
}
}
示例5: Prepare
internal override PreparedDatabaseCommand Prepare(DocumentStore store, Guid etag, int uniqueParameterIdentifier)
{
var values = ConvertAnonymousToProjections(table, projections);
values[table.EtagColumn] = etag;
values[table.ModifiedAtColumn] = DateTimeOffset.Now;
var sql = new SqlBuilder()
.Append("update {0} set {1} where {2}[email protected]{3}",
store.Database.FormatTableNameAndEscape(table.Name),
string.Join(", ", from column in values.Keys select column.Name + "[email protected]" + column.Name + uniqueParameterIdentifier),
table.IdColumn.Name,
uniqueParameterIdentifier)
.Append(!lastWriteWins, "and {0}[email protected]{1}",
table.EtagColumn.Name,
uniqueParameterIdentifier)
.ToString();
var parameters = MapProjectionsToParameters(values, uniqueParameterIdentifier);
AddTo(parameters, "@Id" + uniqueParameterIdentifier, key, SqlTypeMap.Convert(table.IdColumn).DbType, null);
if (!lastWriteWins)
{
AddTo(parameters, "@CurrentEtag" + uniqueParameterIdentifier, currentEtag, SqlTypeMap.Convert(table.EtagColumn).DbType, null);
}
return new PreparedDatabaseCommand
{
Sql = sql,
Parameters = parameters.Values.ToList(),
ExpectedRowCount = 1
};
}
示例6: Can_delete_an_attachment
public IEnumerable<Task> Can_delete_an_attachment()
{
var store = new DocumentStore {Url = Url + Port};
store.Initialize();
var dbname = GenerateNewDatabaseName();
yield return store.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
const string someData = "The quick brown fox jumps over the lazy dog";
var encoding = new UTF8Encoding();
var bytes = encoding.GetBytes(someData);
yield return store.AsyncDatabaseCommands
.ForDatabase(dbname)
.PutAttachmentAsync("123", Guid.Empty, bytes, null);
yield return store.AsyncDatabaseCommands
.ForDatabase(dbname)
.DeleteAttachmentAsync("123", null);
var get = store.AsyncDatabaseCommands
.ForDatabase(dbname)
.GetAttachmentAsync("123");
yield return get;
Assert.AreEqual(null, get.Result);
}
示例7: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
var estore = new EventStore();
var dstore = new DocumentStore();
Action<Command> future = cmd => DiContainer.Current.CommandBus.Submit(cmd);
DiContainer.Current = new DiContainer
{
Store = estore,
DocumentStore = dstore,
CommandBus = new CommandDispatcher(
estore,
e => estore.Store(e),
future
),
Projektor = new Projektor(estore, dstore)
};
if (!estore.All.Any()) GenerateDemoData(estore);
}
示例8: Prepare
internal override PreparedDatabaseCommand Prepare(DocumentStore store, Guid etag, int uniqueParameterIdentifier)
{
var sql = new SqlBuilder()
.Append("delete from {0} where {1} = @Id{2}",
store.Database.FormatTableNameAndEscape(table.Name),
table.IdColumn.Name,
uniqueParameterIdentifier)
.Append(!lastWriteWins,
"and {0} = @CurrentEtag{1}",
table.EtagColumn.Name,
uniqueParameterIdentifier)
.ToString();
var parameters = new Dictionary<string, Parameter>();
AddTo(parameters, "@Id" + uniqueParameterIdentifier, key, SqlTypeMap.Convert(table.IdColumn).DbType, null);
if (!lastWriteWins)
{
AddTo(parameters, "@CurrentEtag" + uniqueParameterIdentifier, currentEtag, SqlTypeMap.Convert(table.EtagColumn).DbType, null);
}
return new PreparedDatabaseCommand
{
Sql = sql,
Parameters = parameters.Values.ToList(),
ExpectedRowCount = 1
};
}
示例9: Prepare
internal override PreparedDatabaseCommand Prepare(DocumentStore store, Guid etag, int uniqueParameterIdentifier)
{
var name = string.Format("{0}_{1}_{2}.bak", design.DocumentType.FullName, key, version);
writer.Write(name, document);
return command.Prepare(store, etag, uniqueParameterIdentifier);
}
示例10: Should_not_cache_the_list_of_databases
public IEnumerable<Task> Should_not_cache_the_list_of_databases()
{
var documentStore = new DocumentStore { Url = Url + Port };
documentStore.Initialize();
var first = GenerateNewDatabaseName();
yield return documentStore.AsyncDatabaseCommands
.EnsureDatabaseExistsAsync(first);
var task = documentStore.AsyncDatabaseCommands
.GetDatabaseNamesAsync();
yield return task;
Assert.IsTrue(task.Result.Contains(first));
var second = GenerateNewDatabaseName();
yield return documentStore.AsyncDatabaseCommands
.EnsureDatabaseExistsAsync(second);
var verify = documentStore.AsyncDatabaseCommands
.GetDatabaseNamesAsync();
yield return verify;
Assert.IsTrue(verify.Result.Contains(second));
}
示例11: 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();
}
}
示例12: 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);
}
}
示例13: Can_delete_an_index_async
public IEnumerable<Task> Can_delete_an_index_async()
{
var dbname = GenerateNewDatabaseName();
var documentStore = new DocumentStore {Url = Url + Port};
documentStore.Initialize();
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
yield return documentStore.AsyncDatabaseCommands
.ForDatabase(dbname)
.PutIndexAsync("Test", new IndexDefinition
{
Map = "from doc in docs.Companies select new { doc.Name }"
}, true);
var verify_put = documentStore.AsyncDatabaseCommands
.ForDatabase(dbname)
.GetIndexNamesAsync(0, 25);
yield return verify_put;
Assert.IsTrue(verify_put.Result.Contains("Test"));
yield return documentStore.AsyncDatabaseCommands
.ForDatabase(dbname)
.DeleteIndexAsync("Test");
var verify_delete = documentStore.AsyncDatabaseCommands
.ForDatabase(dbname)
.GetIndexNamesAsync(0, 25);
yield return verify_delete;
//NOTE: this is failing because Silverlight is caching the response from the first verification
Assert.IsFalse(verify_delete.Result.Contains("Test"));
}
示例14: SetUp
public void SetUp()
{
var path = Path.Combine(Environment.CurrentDirectory, GetType().Name + "Test");
EnsurePath(path);
DocumentStore = new DocumentStore(path);
}
示例15: Replication
public Replication()
{
var store = new DocumentStore();
DocumentConvention Conventions = store.Conventions;
#region failover_behavior
Conventions.FailoverBehavior = FailoverBehavior.AllowReadsFromSecondaries;
#endregion
#region cluster_failover_behavior
Conventions.FailoverBehavior = FailoverBehavior.ReadFromAllWriteToLeader;
#endregion
#region replication_informer
Conventions.ReplicationInformerFactory = (url, jsonRequestFactory, requestTimeMetricGetter) =>
new ReplicationInformer(Conventions, jsonRequestFactory, requestTimeMetricGetter);
#endregion
#region index_and_transformer_replication_mode
Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.Indexes |
IndexAndTransformerReplicationMode.Transformers;
#endregion
}