Raven.Client.Shard.ShardedDocumentStore.OpenSession C# (CSharp) 메소드

OpenSession() 공개 메소드

Opens the session.
public OpenSession ( ) : IDocumentSession
리턴 IDocumentSession
		public override IDocumentSession OpenSession()
		{
			return OpenSessionInternal(null, ShardStrategy.Shards.ToDictionary(x => x.Key, x => x.Value.DatabaseCommands));
		}

Same methods

ShardedDocumentStore::OpenSession ( Raven.Client.Document.OpenSessionOptions sessionOptions ) : IDocumentSession
ShardedDocumentStore::OpenSession ( string database ) : IDocumentSession

Usage Example

예제 #1
0
파일: Index.cs 프로젝트: modulexcite/docs-8
		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();
		}
All Usage Examples Of Raven.Client.Shard.ShardedDocumentStore::OpenSession