using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
public static void Main()
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
using var dbContext = new ApplicationDbContext(options);
var parent = new ParentEntity();
parent.Children.Add(new ChildEntity());
var result = dbContext.Parents
.Select(parent => parent.Children.Select(child => child.Id))
Console.WriteLine("Success");
public sealed class ApplicationDbContext : DbContext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
public DbSet<ParentEntity> Parents {get;set;}
public DbSet<ChildEntity> Children {get;set;}
public sealed class ParentEntity
public ICollection<ChildEntity> Children {get;set;} = new HashSet<ChildEntity>();
public sealed class ChildEntity
public int ParentEntityId {get;set;}
public ParentEntity ParentEntity {get;set;}