CodePlexProject Hosting for Open Source Software
An unexpected error has occured.
There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Closed
IQueryable.Include(...)
dbContext.Set(typeof(Entity)).Include("Collection")
No files are attached
RoMiller wrote Jan 18 at 11:29 PM
ajcvickers wrote Mar 2 at 8:58 PM
public class Blog { public int Id { get; set; } public string Title { get; set; } public virtual ICollection<Post> Posts { get; set; } } public class Post { public int Id { get; set; } public string Title { get; set; } public int BlogId { get; set; } public virtual Blog Blog { get; set; } } public class BlogContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } } class Program { static void Main(string[] args) { using (var context = new BlogContext()) { var blog = new Blog {Title = "One Unicorn"}; context.Posts.Add(new Post { Title = "Open source FTW1", Blog = blog }); context.Posts.Add(new Post { Title = "Open source FTW2", Blog = blog }); context.Posts.Add(new Post { Title = "Open source FTW3", Blog = blog }); context.SaveChanges(); } using (var context = new BlogContext()) { context.Configuration.LazyLoadingEnabled = false; var blogs = context.Set(typeof (Blog)).Include("Posts"); foreach (Blog blog in blogs) { Console.WriteLine("Blog: {0}", blog.Title); foreach (var post in blog.Posts) { Console.WriteLine(" Post: {0}", post.Title); } } } } }
ajcvickers wrote Mar 11 at 11:28 PM
Sign in to add a comment
Keyboard shortcuts are available for this page.