Created
July 22, 2011 12:17
-
-
Save gamlerhart/1099334 to your computer and use it in GitHub Desktop.
RavenSafeByDefault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session.Advanced.Conventions.MaxNumberOfRequestsPerSession = 50; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (var blogPost in dotNetBlogPosts.Take(5000)) | |
{ | |
// do something | |
countPosts++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number of blog posts 2000 | |
Iterated through 128 posts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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