Home
Options

ThenInclude

How to get ThenInclude to work in LINQPad 5? I'm getting the error " does not contain a definition for 'ThenInclude'"

Comments

  • Options
    What version of EF are you using? I only think EF core has this.
  • Options
    Core 2.0. . How to get it to work with linqpad?
  • Options
    edited February 2018
    The following works for me with the EF Core 2.0 driver:

    Blog.Take (100).Include (b => b.Posts).ThenInclude (p => p.Blog)

    Just as with Visual Studio, you won't see the ThenInclude method appear in the autocompletion listing due to a bug in Roslyn, although it compiles and runs correctly. See https://docs.microsoft.com/en-us/ef/core/querying/related-data for details.

    Here is how I've defined Blog and Posts in my EF Core 2 project in Visual Studio:
    public class BloggingContext : DbContext
    {
        public DbSet<Blog> Blog { get; set; }
        public DbSet<Post> Posts { get; set; }
    
        protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer (@"Server=.;Database=BlogTest;Trusted_Connection=True;");
            optionsBuilder.EnableSensitiveDataLogging ();
        }
    }
    
    public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }
    
        public virtual List<Post> Posts { get; set; }
    }
    
    public class Post
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
    
        public int BlogId { get; set; }
        public virtual Blog Blog { get; set; }
    }
    
    Can you try the same?
Sign In or Register to comment.