当前位置: 首页>>代码示例>>C#>>正文


C# ShardedDocumentStore.OpenSession方法代码示例

本文整理汇总了C#中Raven.Client.Shard.ShardedDocumentStore.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# ShardedDocumentStore.OpenSession方法的具体用法?C# ShardedDocumentStore.OpenSession怎么用?C# ShardedDocumentStore.OpenSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Client.Shard.ShardedDocumentStore的用法示例。


在下文中一共展示了ShardedDocumentStore.OpenSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Index

		public Index()
		{
			#region store
			var shards = new Dictionary<string, IDocumentStore>
			             	{
			             		{"Asia", new DocumentStore {Url = "http://localhost:8080"}},
			             		{"Middle East", new DocumentStore {Url = "http://localhost:8081"}},
			             		{"America", new DocumentStore {Url = "http://localhost:8082"}},
			             	};

			var shardStrategy = new ShardStrategy(shards)
				.ShardingOn<Company>(company => company.Region)
				.ShardingOn<Invoice>(x => x.CompanyId);

			var documentStore = new ShardedDocumentStore(shardStrategy).Initialize();

			#endregion

			#region SaveEntities
			using (var session = documentStore.OpenSession())
			{
				var asian = new Company { Name = "Company 1", Region = "Asia" };
				session.Store(asian);
				var middleEastern = new Company { Name = "Company 2", Region = "Middle-East" };
				session.Store(middleEastern);
				var american = new Company { Name = "Company 3", Region = "America" };
				session.Store(american);

				session.Store(new Invoice { CompanyId = american.Id, Amount = 3, IssuedAt = DateTime.Today.AddDays(-1) });
				session.Store(new Invoice { CompanyId = asian.Id, Amount = 5, IssuedAt = DateTime.Today.AddDays(-1) });
				session.Store(new Invoice { CompanyId = middleEastern.Id, Amount = 12, IssuedAt = DateTime.Today });
				session.SaveChanges();
			}

			#endregion

			#region Query
			using (var session = documentStore.OpenSession())
			{
				//get all, should automagically retrieve from each shard
				var allCompanies = session.Query<Company>()
					.Customize(x => x.WaitForNonStaleResultsAsOfNow())
					.Where(company => company.Region == "Asia")
					.ToArray();

				foreach (var company in allCompanies)
					Console.WriteLine(company.Name);
			}

			#endregion

			documentStore.Dispose();
		}
开发者ID:modulexcite,项目名称:docs-8,代码行数:53,代码来源:Index.cs

示例2: Main

        static void Main(string[] args)
        {
            var shards = new Dictionary<string, IDocumentStore>
                {
                    { "one", new DocumentStore { Url = "http://localhost:8079", } },
                    { "two", new DocumentStore { Url = "http://localhost:8078", } },
                };

            var shardStrategy = new ShardStrategy(shards)
                .ShardingOn<User>()
                .ShardingOn<Story>(x => x.UserId);

            using (var store = new ShardedDocumentStore(shardStrategy).Initialize())
            {
                //using (var session = store.OpenSession())
                //{
                //	var user = new User { Name = "Ayende" };
                //	session.Store(user);
                //	session.Store(new Story { UserId = user.Id });
                //	session.SaveChanges();
                //}

                using (var session = store.OpenSession())
                {
                    var load = session.Query<Story>()
                        .Where(x => x.UserId == "two/users/1")
                        .ToList();

                    Console.WriteLine(load[0].UserId);
                }
            }
        }
开发者ID:ayende,项目名称:courses-trondheim-sep-2012,代码行数:32,代码来源:Program.cs

示例3: CanIgnoreParallel

		public void CanIgnoreParallel()
		{
			using (GetNewServer())
			{
				var shardingStrategy = new ShardStrategy(new Dictionary<string, IDocumentStore>
				{
					{"one", new DocumentStore {Url = "http://localhost:8079"}},
					{"two", new DocumentStore {Url = "http://localhost:8078"}},
				})
				{
					ShardAccessStrategy = new ParallelShardAccessStrategy()
				};
				shardingStrategy.ShardAccessStrategy.OnError += (commands, request, exception) => request.Query != null;

				using (var docStore = new ShardedDocumentStore(shardingStrategy).Initialize())
				{
					using (var session = docStore.OpenSession())
					{
						session.Query<AccurateCount.User>()
							.ToList();
					}
				}

			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:25,代码来源:ShardingFailure.cs

示例4: CanDisableQueryResultsTrackingForShardedDocumentQuery

		public void CanDisableQueryResultsTrackingForShardedDocumentQuery()
		{

			using (GetNewServer(8079))
			using (GetNewServer(8078))
			using (var store = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
			{
				{"1", CreateDocumentStore(8079)},
				{"2", CreateDocumentStore(8078)},
			})))
			{
				store.Initialize();

				using (var session = store.OpenSession())
				{
					session.Store(new Item());
					session.Store(new Item());

					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var items = session.Query<Item>().Customize(x => x.NoTracking().WaitForNonStaleResults()).ToList();

					Assert.Equal(2, items.Count);
					Assert.Equal(0, ((InMemoryDocumentSessionOperations) session).NumberOfEntitiesInUnitOfWork);
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:30,代码来源:RavenDB_790.cs

示例5: Main

        private static void Main()
        {
            var shards = new Dictionary<string, IDocumentStore>
            {
                {"_", new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "Shop"}}, //existing data
                {"ME", new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "Shop_ME"}},
                {"US", new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "Shop_US"}},
            };

            var shardStrategy = new ShardStrategy(shards)
                .ShardingOn<Customer>(c => c.Region)
                .ShardingOn<Invoice>(i => i.Customer);

            var x = new ShardedDocumentStore(shardStrategy).Initialize();
            using (var s = x.OpenSession())
            {
                var customer = new Customer
                {
                    Region = "US"
                };
                s.Store(customer);
                s.Store(new Invoice
                {
                    Customer = customer.Id
                });
                s.SaveChanges();
            }
        }
开发者ID:jrusbatch,项目名称:ravendb,代码行数:28,代码来源:Program.cs

示例6: Sharding

        public Sharding()
        {
            #region intro
            var shards = new Dictionary<string, IDocumentStore>
                         	{
                         		{"Asia", new DocumentStore {Url = "http://localhost:8080"}},
                         		{"Middle East", new DocumentStore {Url = "http://localhost:8081"}},
                         		{"America", new DocumentStore {Url = "http://localhost:8082"}},
                         	};

            var shardStrategy = new ShardStrategy
                                    {
                                        ShardAccessStrategy = new ParallelShardAccessStrategy(),
                                        ShardResolutionStrategy = new ShardResolutionByRegion(),
                                    };

            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
            using (var session = documentStore.OpenSession())
            {
                //store 3 items in the 3 shards
                session.Store(new Company {Name = "Company 1", Region = "Asia"});
                session.Store(new Company {Name = "Company 2", Region = "Middle East"});
                session.Store(new Company {Name = "Company 3", Region = "America"});
                session.SaveChanges();

                //get all, should automagically retrieve from each shard
                var allCompanies = session.Query<Company>()
                    .Customize(x => x.WaitForNonStaleResultsAsOfNow()).ToArray();

                foreach (var company in allCompanies)
                    Console.WriteLine(company.Name);
            }
            #endregion
        }
开发者ID:kprog,项目名称:docs,代码行数:34,代码来源:Sharding.cs

示例7: Main

		static void Main()
		{
			var shards = new Dictionary<string, IDocumentStore>
			             	{
			             		{"one", new DocumentStore {Url = "http://localhost:8079"}},
			             		{"two", new DocumentStore {Url = "http://localhost:8078"}},
			             		{"three", new DocumentStore {Url = "http://localhost:8077"}},
			             	};

			var shardStrategy = new ShardStrategy(shards)
				.ShardingOn<Company>()
				.ShardingOn<Invoice>(x => x.CompanyId);

			using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize())
			{
				new InvoicesAmountByDate().Execute(documentStore);

				using (var session = documentStore.OpenSession())
				{
					var asian = new Company { Name = "Company 1" };
					session.Store(asian);
					var middleEastern = new Company { Name = "Company 2" };
					session.Store(middleEastern);
					var american = new Company { Name = "Company 3" };
					session.Store(american);

					session.Store(new Invoice { CompanyId = american.Id, Amount = 3, IssuedAt = DateTime.Today.AddDays(-1) });
					session.Store(new Invoice { CompanyId = asian.Id, Amount = 5, IssuedAt = DateTime.Today.AddDays(-1) });
					session.Store(new Invoice { CompanyId = middleEastern.Id, Amount = 12, IssuedAt = DateTime.Today });
					session.SaveChanges();
				}


				using (var session = documentStore.OpenSession())
				{
					var reduceResults = session.Query<InvoicesAmountByDate.ReduceResult, InvoicesAmountByDate>()
						.ToList();

					foreach (var reduceResult in reduceResults)
					{
						string dateStr = reduceResult.IssuedAt.ToString("MMM dd, yyyy", CultureInfo.InvariantCulture);
						Console.WriteLine("{0}: {1}", dateStr, reduceResult.Amount);
					}
					Console.WriteLine();
				}
			}
		}
开发者ID:AleksanderGondek,项目名称:GUT_IronTester,代码行数:47,代码来源:Program.cs

示例8: get_metadata_for_sharded

		public void get_metadata_for_sharded()
		{
			var server1 = GetNewServer(8079);
			var server2 = GetNewServer(8078);
			var shards = new List<IDocumentStore>
			{
				new DocumentStore {Identifier = "Shard1", Url = server1.Configuration.ServerUrl},
				new DocumentStore {Identifier = "Shard2", Url = server2.Configuration.ServerUrl}
			}
				.ToDictionary(x => x.Identifier, x => x);

			var shardStrategy = new ShardStrategy(shards);
			shardStrategy.ShardingOn<Profile>(x => x.Location);

			using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
			{
				shardedDocumentStore.Initialize();

				var profile = new Profile {Name = "Test", Location = "Shard1"};
				var profile2 = new Profile {Name = "Test2", Location = "Shard2"};

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					documentSession.Store(profile, profile.Id);
					documentSession.Store(profile2, profile2.Id);
					documentSession.SaveChanges();
				}
				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					var correctId = profile.Id;
					var correctId2 = profile2.Id;

					documentSession.Store(profile, profile.Id);
					var metaData = documentSession.Advanced.GetMetadataFor(profile);
					var metaData2 = documentSession.Advanced.GetMetadataFor(profile2);

					Assert.NotNull(metaData);
					Assert.NotNull(metaData2);
					Assert.Equal(correctId, profile.Id);
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:42,代码来源:RavenDB-3465.cs

示例9: OverwritingExistingDocumentGeneratesWrongIdWithShardedDocumentStore

        public void OverwritingExistingDocumentGeneratesWrongIdWithShardedDocumentStore()
        {
            using (var store1 = NewRemoteDocumentStoreWithUrl(8079, ravenDbServer: GetNewServer(8079)))
            {
                using (var store2 = NewRemoteDocumentStoreWithUrl(8078, ravenDbServer: GetNewServer(8078)))
                {
                    var shards = new List<IDocumentStore> { 
                        new DocumentStore { Identifier="Shard1", Url = store1.Url}, 
                        new DocumentStore { Identifier="Shard2", Url = store2.Url} }
                            .ToDictionary(x => x.Identifier, x => x);

                    var shardStrategy = new ShardStrategy(shards);
                    shardStrategy.ShardingOn<Profile>(x => x.Location);

                    using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
                    {
                        shardedDocumentStore.Initialize();

                        var profile = new Profile { Name = "Test", Location = "Shard1" };

                        using (var documentSession = shardedDocumentStore.OpenSession())
                        {
                            documentSession.Store(profile, profile.Id);
                            documentSession.SaveChanges();
                        }

                        using (var documentSession = shardedDocumentStore.OpenSession())
                        {
                            var correctId = profile.Id;

                            documentSession.Store(profile, profile.Id);

                            Assert.Equal(correctId, profile.Id);
                        }
                    }
                }
            }
        }
开发者ID:hero106wen,项目名称:ravendb,代码行数:38,代码来源:ShardedIdGenerationTest.cs

示例10: Can_insert_into_two_sharded_servers

        public void Can_insert_into_two_sharded_servers()
        {
            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards))
            {
                documentStore.Initialize();

                using (var session = documentStore.OpenSession())
                {
                	session.Store(company1);
					session.Store(company2);
					session.SaveChanges();
                }
            }
        }
开发者ID:nzdunic,项目名称:ravendb,代码行数:14,代码来源:When_Using_Sharded_Servers.cs

示例11: OverwritingExistingDocumentGeneratesWrongIdWithShardedDocumentStore

        public void OverwritingExistingDocumentGeneratesWrongIdWithShardedDocumentStore()
        {
			var server1 = GetNewServer(8079);
			var server2 = GetNewServer(8078);
			var shards = new Dictionary<string, IDocumentStore>
			{
				{"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}},
				{"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}},
			};



	        var shardStrategy = new ShardStrategy(shards);
	        shardStrategy.ShardingOn<Profile>(x => x.Location);

	        using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
	        {
		        shardedDocumentStore.Initialize();

		        var profile = new Profile {Name = "Test", Location = "Shard1"};

		        using (var documentSession = shardedDocumentStore.OpenSession())
		        {
			        documentSession.Store(profile, profile.Id);
			        documentSession.SaveChanges();
		        }

		        using (var documentSession = shardedDocumentStore.OpenSession())
		        {
			        var correctId = profile.Id;

			        documentSession.Store(profile, profile.Id);

			        Assert.Equal(correctId, profile.Id);
		        }
	        }
        }
开发者ID:GorelH,项目名称:ravendb,代码行数:37,代码来源:RavenDB3075.cs

示例12: Main

		static void Main()
		{
			var shards = new Shards
			             	{
			             		new DocumentStore {Url = "http://localhost:8080", Identifier = "Posts"},
			             		new DocumentStore
			             			{
			             				Url = "http://localhost:8081",
			             				Identifier = "Users",
			             				Conventions = {DocumentKeyGenerator = user => "users/" + ((User) user).Name}
			             			}
			             	};

			var shardStrategy = new ShardStrategy
			{
				ShardAccessStrategy = new ParallelShardAccessStrategy(),
				ShardSelectionStrategy = new BlogShardSelectionStrategy(),
				ShardResolutionStrategy = new BlogShardResolutionStrategy()
			};

			using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
			{
				using (var session = documentStore.OpenSession())
				{
					var user = new User { Name = "PastyGeek" };
					session.Store(user);
					session.SaveChanges();

					var post = new Post
					{
						AuthorId = user.Id,
						Name = user.Name,
						BlogId = "blogs/1",
						Title = "More CodeMash Gloating!",
						Body = "You wouldn't believe how much more fun I'm having than you!",
						PostDate = DateTime.Now,
						Tags = new List<string> { "codemash", "gloating" }
					};
					session.Store(post);
					session.SaveChanges();
				}
			}
		}
开发者ID:reverentgeek,项目名称:RavenDB.Demos,代码行数:43,代码来源:Program.cs

示例13: get_metadata_for_async_sharded

		public async Task get_metadata_for_async_sharded()
		{
			var server1 = GetNewServer(8079);
			var server2 = GetNewServer(8078);
			var shards = new Dictionary<string, IDocumentStore>
			{
				{"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}},
				{"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}},
			};

			var shardStrategy = new ShardStrategy(shards);
			shardStrategy.ShardingOn<Profile>(x => x.Location);

			using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
			{
				shardedDocumentStore.Initialize();

				var profile = new Profile {Name = "Test", Location = "Shard1"};
				var profile2 = new Profile {Name = "Test2", Location = "Shard2"};

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					documentSession.Store(profile, profile.Id);
					documentSession.Store(profile2, profile2.Id);
					documentSession.SaveChanges();
				}

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					var metaData = documentSession.Advanced.GetMetadataFor(profile);
				}
				using (var documentSession = shardedDocumentStore.OpenAsyncSession())
				{
					//var data = await documentSession.LoadAsync<Profile>(profile.Id);
					var metaData = await documentSession.Advanced.GetMetadataForAsync(profile);
					var metaData2 = await documentSession.Advanced.GetMetadataForAsync(profile2);

					Assert.NotNull(metaData);
					Assert.NotNull(metaData2);
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:42,代码来源:RavenDB-3465.cs

示例14: Can_insert_into_two_sharded_servers

        public void Can_insert_into_two_sharded_servers()
        {
            var serverPortsStoredUpon = new List<string>();

            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards))
            {
                documentStore.Stored += (storeServer, storeEntity) => serverPortsStoredUpon.Add(storeServer);
                documentStore.Initialize();

                using (var session = documentStore.OpenSession())
                {
                	session.Store(company1);
					session.Store(company2);
					session.SaveChanges();
                }
            }

			Assert.Contains("Shard1", serverPortsStoredUpon[0]);
			Assert.Contains("Shard2", serverPortsStoredUpon[1]);
        }
开发者ID:VirtueMe,项目名称:ravendb,代码行数:20,代码来源:When_Using_Sharded_Servers.cs

示例15: CanOverrideTheShardIdGeneration

		public void CanOverrideTheShardIdGeneration()
		{
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				foreach (var shard in shards)
				{
					shard.Value.Conventions.DocumentKeyGenerator = c => ((Company)c).Name;
				}

				using (var session = documentStore.OpenSession())
				{
					session.Store(company1);
					session.Store(company2);

					Assert.Equal("Shard1/companies/1", company1.Id);
					Assert.Equal("Shard2/companies/2", company2.Id);
				}
			}
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:21,代码来源:WhenUsingShardedServers.cs


注:本文中的Raven.Client.Shard.ShardedDocumentStore.OpenSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。