Skip to content

Instantly share code, notes, and snippets.

@mikecole
Created September 20, 2013 15:40
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 mikecole/6639490 to your computer and use it in GitHub Desktop.
Save mikecole/6639490 to your computer and use it in GitHub Desktop.
Lazy Loading Issue
var posts = context.Posts.ToArray();
var model = (from post in posts
select new PostsViewModel
{
Title = post.Title,
Url = post.Url,
AuthorName = post.Author.Name,
AuthorTwitterHandle = post.Author.TwitterHandle
}).ToArray();
public class Post : EntityBase
{
public string Title { get; set; }
public string Url { get; set; }
public virtual Author Author { get; set; }
}
public class Author : EntityBase
{
public Author()
{
Posts = new Collection<Post>();
}
public string Name { get; set; }
public string TwitterHandle { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment