コード例 #1
0
        private void BackupDocs <T>(bool append, int page = 0)
        {
            Raven.Client.RavenQueryStatistics stats = null;
            var path = Server.MapPath(ConfigurationManager.AppSettings["backuppath"]).TrimEnd('\\') + "\\" + typeof(T).Name + ".json";

            FileStream fs = null;

            if (!append)
            {
                fs = System.IO.File.Create(path);
            }
            else
            {
                fs = System.IO.File.Open(path, FileMode.Append);
            }

            using (StreamWriter w = new StreamWriter(fs))
            {
                using (var session = DB.Instance.GetSession())
                {
                    var docs = session.Query <T>().Statistics(out stats).Skip(page * 1024).Take(1024).ToList();
                    foreach (var d in docs)
                    {
                        w.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(d));
                    }
                }
            }

            if (stats != null && (stats.TotalResults - ((page + 1) * 1024)) > 0)
            {
                BackupDocs <T>(true, page + 1);
            }
        }
コード例 #2
0
		public void CanPerformDynamicQueryUsingClientLinqQueryWithNestedCollection()
		{
			var blogOne = new Blog
			{
				Title = "one",
				Category = "Ravens",
				 Tags = new BlogTag[]{
					 new BlogTag(){ Name = "Birds" }
				 }
			};
			var blogTwo = new Blog
			{
				Title = "two",
				Category = "Rhinos",
				Tags = new BlogTag[]{
					 new BlogTag(){ Name = "Mammals" }
				 }
			};
			var blogThree = new Blog
			{
				Title = "three",
				Category = "Rhinos",
				Tags = new BlogTag[]{
					 new BlogTag(){ Name = "Mammals" }
				 }
			};

			using(var store = this.NewDocumentStore())
			{               
				using (var s = store.OpenSession())
				{
					s.Store(blogOne);
					s.Store(blogTwo);
					s.Store(blogThree);
					s.SaveChanges();
				}

				using (var s = store.OpenSession())
				{
				  var stats = new Raven.Client.RavenQueryStatistics();
					var results = s.Query<Blog>()
            .Statistics(out stats)
						.Customize(x => x.WaitForNonStaleResultsAsOfNow(TimeSpan.FromSeconds(5)))
						.Where(x => x.Tags.Any(y=>y.Name == "Birds"))
						.ToArray();

          

					Assert.Equal(1, results.Length);
					Assert.Equal("one", results[0].Title);
					Assert.Equal("Ravens", results[0].Category);
				}
			}
		}
コード例 #3
0
        public void CanPerformDynamicQueryUsingClientLinqQueryWithNestedCollection()
        {
            var blogOne = new Blog
            {
                Title    = "one",
                Category = "Ravens",
                Tags     = new BlogTag[] {
                    new BlogTag()
                    {
                        Name = "Birds"
                    }
                }
            };
            var blogTwo = new Blog
            {
                Title    = "two",
                Category = "Rhinos",
                Tags     = new BlogTag[] {
                    new BlogTag()
                    {
                        Name = "Mammals"
                    }
                }
            };
            var blogThree = new Blog
            {
                Title    = "three",
                Category = "Rhinos",
                Tags     = new BlogTag[] {
                    new BlogTag()
                    {
                        Name = "Mammals"
                    }
                }
            };

            using (var store = this.NewDocumentStore())
            {
                using (var s = store.OpenSession())
                {
                    s.Store(blogOne);
                    s.Store(blogTwo);
                    s.Store(blogThree);
                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    var stats   = new Raven.Client.RavenQueryStatistics();
                    var results = s.Query <Blog>()
                                  .Statistics(out stats)
                                  .Customize(x => x.WaitForNonStaleResultsAsOfNow(TimeSpan.FromSeconds(5)))
                                  .Where(x => x.Tags.Any(y => y.Name == "Birds"))
                                  .ToArray();



                    Assert.Equal(1, results.Length);
                    Assert.Equal("one", results[0].Title);
                    Assert.Equal("Ravens", results[0].Category);
                }
            }
        }