using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
public class BloggingContext : DbContext
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlServer(@"Server=.\SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;");
protected override void OnModelCreating(ModelBuilder modelBuilder)
base.OnModelCreating(modelBuilder);
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; set; } = new List<Post>();
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
public static void Main()
using var context = new BloggingContext();
var query = context.Set<Blog>()
.Where(b => b.Posts.Any(p => p.Title.Contains("abc")))
.Include(b => b.Posts.Where(p => p.Title.Contains("abc")))
var query2 = (Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<Blog>)query;
Console.WriteLine(query2.DebugView.Query);