using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
static DbContextOptions<Context> options;
static void Main(string[] args)
options = new DbContextOptionsBuilder<Context>()
.UseInMemoryDatabase(databaseName: "devs_database")
using (Context context = new Context(options))
var dep = context.Departments.Add(new Department(1, "A"));
context.Developers.Add(new Developer(1, "aa", dep.Entity));
context.Developers.Add(new Developer(2, "ab", dep.Entity));
dep = context.Departments.Add(new Department(2, "B"));
context.Developers.Add(new Developer(3, "ba", dep.Entity));
context.Developers.Add(new Developer(4, "bb", dep.Entity));
Console.WriteLine(string.Join(", ",GetDevs("A")));
public static List<Developer> GetDevs(string DepartmentName)
using Context ctx = new(options);
return ctx.Developers.Include(d=>d.Department).Where(d => d.Department.DepartmentName == DepartmentName).ToList();
public class Context : DbContext
public DbSet<Developer> Developers { get; set; }
public DbSet<Department> Departments { get; set; }
public Context(DbContextOptions<Context> options)
public record Developer(int Id, string FirstName="", Department Department=null)
internal Developer() : this(0) { }
public record Department(int Id, string DepartmentName="")
internal Department() : this(0) { }