Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Issue: Non-generic IQueryable.Include does not work [786]

$
0
0
Hi,

it seems `IQueryable.Include(...)` does not work for collections when using non-generic DbSet. Eg. `dbContext.Set(typeof(Entity)).Include("Collection")` will not load items included in the collection.
Comments: @djanosik Thanks for reporting this issue. Unfortunately we have been unable to reproduce it--Include for non-generic DbSets seems to work fine in my testing. Could you please provide more information about how to reproduce the problem--for example, a simple model where this fails would be very useful. Also, if you get an exception then please provide the message and full stack trace. In case it helps, the code I used to attempt to repro the issue is below. ``` 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); } } } } } ```

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>