Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created May 3, 2011 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/952637 to your computer and use it in GitHub Desktop.
Save SamSaffron/952637 to your computer and use it in GitHub Desktop.
var q1 = System.Data.Linq.CompiledQuery.Compile(
(DBContext db, Badge bg, int pg) =>
(
from u2b in db.Users2Badges
join b in db.Badges on u2b.BadgeId equals b.Id
from post in db.Posts.Where(p => p.Id == u2b.ReasonId && b.BadgeReasonType == BadgeReasonType.Post && p.DeletionDate == null).DefaultIfEmpty()
from tag in db.Tags.Where(t => t.Id == u2b.ReasonId && b.BadgeReasonType == BadgeReasonType.Tag).DefaultIfEmpty()
where u2b.BadgeId == b.Id
orderby u2b.Date descending
select new StackOverflow.ViewModel.BadgesViewModel.BadgeInfo
{
Users2Badge = u2b,
Post = post,
Tag = tag,
User = u2b.User,
Badge = bg
}
).Skip((pg - 1)*60).Take(60)
);
var q2 = System.Data.Linq.CompiledQuery.Compile(
(DBContext db, Badge bg) =>
(
from u2b in db.Users2Badges
join b in db.Badges on u2b.BadgeId equals b.Id
from post in db.Posts.Where(p => p.Id == u2b.ReasonId && b.BadgeReasonType == BadgeReasonType.Post && p.DeletionDate == null).DefaultIfEmpty()
from tag in db.Tags.Where(t => t.Id == u2b.ReasonId && b.BadgeReasonType == BadgeReasonType.Tag).DefaultIfEmpty()
where u2b.BadgeId == b.Id
orderby u2b.Date descending
select new StackOverflow.ViewModel.BadgesViewModel.BadgeInfo
{
Users2Badge = u2b,
Post = post,
Tag = tag,
User = u2b.User,
Badge = bg
}
).Count()
);
q1(Current.DB, badge,1);
q2(Current.DB, badge);
using (Current.MiniProfiler.Step("test1"))
{
q1(Current.DB, badge, 1);
q2(Current.DB, badge);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment