本文整理汇总了C#中Raven.Client.Shard.ShardedDocumentStore.ShardedBulkInsert方法的典型用法代码示例。如果您正苦于以下问题:C# ShardedDocumentStore.ShardedBulkInsert方法的具体用法?C# ShardedDocumentStore.ShardedBulkInsert怎么用?C# ShardedDocumentStore.ShardedBulkInsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Client.Shard.ShardedDocumentStore
的用法示例。
在下文中一共展示了ShardedDocumentStore.ShardedBulkInsert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: bulk_insert_sharded
public void bulk_insert_sharded(string databaseName1, string databaseName2)
{
var server1 = GetNewServer(8079);
var server2 = GetNewServer(8078);
var shards = new Dictionary<string, IDocumentStore>
{
{"Shard1", new DocumentStore {Url = server1.Configuration.ServerUrl, DefaultDatabase = databaseName1}},
{"Shard2", new DocumentStore {Url = server2.Configuration.ServerUrl, DefaultDatabase = databaseName2}}
};
var shardStrategy = new ShardStrategy(shards);
shardStrategy.ShardingOn<Profile>(x => x.Location);
using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
{
shardedDocumentStore.Initialize();
var entity1 = new Profile {Id = "bulk1", Name = "Hila", Location = "Shard1"};
var entity2 = new Profile {Name = "Jay", Location = "Shard2"};
var entity3 = new Profile {Name = "Jay", Location = "Shard1"};
using (var bulkInsert = shardedDocumentStore.ShardedBulkInsert())
{
bulkInsert.Store(entity1);
bulkInsert.Store(entity2);
bulkInsert.Store(entity3);
}
}
using (var store1 = new DocumentStore { Url = server1.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = databaseName1 }.Initialize())
{
using (var session = store1.OpenSession())
{
var docs = session.Load<Profile>("Shard1/bulk1");
Assert.Equal("Shard1", docs.Location);
var docs2 = session.Load<Profile>("Shard1/profiles/2");
Assert.Equal("Shard1", docs2.Location);
var totalDocs = session.Query<Profile>()
.Customize(x => x.WaitForNonStaleResults())
.ToList();
Assert.Equal(2, totalDocs.Count);
}
}
using (var store2 = new DocumentStore { Url = server2.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = databaseName2 }.Initialize())
{
using (var session = store2.OpenSession())
{
var docs = session.Load<Profile>("Shard2/profiles/1");
Assert.Equal("Shard2", docs.Location);
var totalDocs = session.Query<Profile>()
.Customize(x => x.WaitForNonStaleResults())
.ToList();
Assert.Equal(1, totalDocs.Count);
}
}
}