Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RavenSafeByDefault
public class BlogPost
{
public BlogPost(string title)
{
Title = title;
}
public string Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public string Category { get; set; }
}
public class Comment
{
public string BlogPostId { get; set; }
public string Content { get; set; }
}
session.Advanced.Conventions.MaxNumberOfRequestsPerSession = 50;
for (int i = 0; i < 50000; i++)
{
var blogPost = new BlogPost("Programming-Blah")
{
Content = "Tech stuff",
Category = ".NET"
};
session.Store(blogPost);
}
session.SaveChanges();
var dotNetBlogPosts = from p in session.Query<BlogPost>()
.Customize(o=>o.WaitForNonStaleResultsAsOfLastWrite())
where p.Category == ".NET"
select p;
foreach (var blogPost in dotNetBlogPosts.Take(50))
{
// do something with blogs
}
foreach (var blogPost in dotNetBlogPosts.Take(5000))
{
// do something
countPosts++;
}
var dotNetBlogPosts = from p in session.Query<BlogPost>()
where p.Category == ".NET"
select p;
Console.Out.WriteLine("Number of blog posts {0}",dotNetBlogPosts.Count());
var countPosts = 0;
foreach (var blogPost in dotNetBlogPosts)
{
// do something
countPosts++;
}
Console.Out.WriteLine("Iterated through {0} posts", countPosts);
var dotNetBlogPosts = from p in session.Query<BlogPost>()
where p.Category == ".NET"
select p;
foreach (var blogPost in dotNetBlogPosts.Take(50))
{
var blogId = blogPost.Id;
// This is most of the time not that obvious but hidden
// in further methods
var commentsForPost = from c in session.Query<Comment>()
where c.BlogPostId == blogId
select c;
DoSomethingWithComments(commentsForPost);
}
Number of blog posts 2000
Iterated through 128 posts
for (int i = 0; i < 2000; i++)
{
var blogPost = new BlogPost("Programming-Blah")
{
Content = "Tech stuff",
Category = ".NET"
};
session.Store(blogPost);
session.Store(new Comment()
{
BlogPostId = blogPost.Id,
Content = "Comment"
});
session.Store(new Comment()
{
BlogPostId = blogPost.Id,
Content = "Other Comment"
});
}
session.SaveChanges();
foreach (var blogPost in dotNetBlogPosts.Take(50))
{
// do something
countPosts++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.