I have an `Activity` model that pulls in models from 7 or so different types of models. Those models have their relationships too, which the activity feed needs to be able to display the information I want. This means I have roughly 20 includes in my query. I've only been doing this for 8 months or so, and I've read about compiled queries, stored procedures, and how all those includes are probably killing me. I've also read that I could change my code first models to be `virtual` so that it can do lazy loading, but I'm concerned that all those database calls would kill my site if I got a large volume of users.

First the model

```
public class Activity
{
    public int ActivityID { get; set; }
    public int ActivityTypeID { get; set; }
    public int ContributorID { get; set; }
    public int UserID { get; set; }
    public int? ProjectID { get; set; }
    public int? ProjectDocID { get; set; }
    public int? CommentID { get; set; }
    public int? BookID { get; set; }
    public int? BookReviewID { get; set; }
    public DateTime DateCreated { get; set; }
    public Comment Comment { get; set; }
    public ProjectDoc ProjectDoc { get; set; }
    public Project Project { get; set; }
    public Book Book { get; set; }
    public BookReview BookReview { get; set; }
    public ActivityType ActivityType { get; set; }
    [ForeignKey("ContributorID")]
    public User Contributor { get; set; }
    [ForeignKey("UserID")]
    public User User { get; set; }
    public ICollection<ActivityLike> ActivityLike { get; set; }
    public ICollection<ActivityComment> ActivityComment { get; set; }
}

```

Now the query

```
 var activity = db.Activities
                .Include(i => i.Contributor.BookStatus)
                .Include(i => i.ActivityType)
                .Include(i => i.ActivityLike.Select(y => y.User))
                .Include(i => i.ActivityComment.Select(y => y.User))
                .Include(i => i.Project.ProjectFollower)
                .Include(i => i.Project.View)
                .Include(i => i.Project.ProjectType)
                .Include(i => i.Project.User)
                .Include(i => i.Project.ProjectTag.Select(v => v.Tag))
                .Include(i => i.Project.ProjectCategory.Select(v => v.Category))
                .Include(i => i.Project.ProjectCharacteristic.Select(v => v.Characteristic))
                .Include(i => i.Project.ProjectDoc.Select(v => v.ProjectDocVote))
                .Include(i => i.Project.ProjectDoc.Select(v => v.User))
                .Include(i => i.Comment.User)
                .Include(i => i.Book.Author)
                .Include(i => i.Book.BookReview.Select(v => v.User))
                .Include(i => i.Book.BookReview.Select(v => v.BookReviewVote))
                .Include(i => i.Book.BookCharacteristic.Select(v => v.Characteristic))
                .Include(i => i.Contributor.Followers)
                .Where(u =>
                    u.Contributor.Followers.FirstOrDefault(x => x.FollowerID == WebSecurity.CurrentUserId) != null
                )
                .OrderByDescending(d => d.DateCreated)
                .Skip(offset)
                .Take(results)
                .ToList();

```

This winds up being like 6600 lines of SQL (or whatever it is).

The first time this runs it takes 10-16 seconds. And because I am using `Skip()` and infinite scroll with jquery, every single ajax call takes 10-12 seconds the first time. So if I'm getting 10 results per go and there's 100 results then that's over 100 seconds of wait time, which is awful. Now the next time the user visits that page in a short time period it's very quick.

So how should I improve this query and can you provide specifically how to do so and explain the solution because I've had difficulty understanding compiled queries and what not. The only reason I've been able to get this far is because EF makes it easy... which obviously has a cost.

Please pardon and misused lingo.