using System; using System.Linq; RuntimeState.Reset(); User? user = new() { DBUser = new DBUser { ID = 1 } }; using IS0AUTTSTContext db = GetDbContext(); System.Collections.Generic.List list = db.TestRuns .Where(t => t.ID > 0 && t.Definition!.Application!.Deleted == false) .ToList(); //List apps = []; if (user != null && user.IsInRole("Basic")) { List apps = []; System.Collections.Generic.List appUsers = db.ApplicationUsers .Where(au => au.UserID == user.DBUser!.ID) .ToList(); apps.AddRange( appUsers.Where(au => au != null) .Select(au => au.AppID) .ToList() ); } Console.WriteLine("Done"); static IS0AUTTSTContext GetDbContext() { return new IS0AUTTSTContext(); } public static class RuntimeState { public static bool RoleWasChecked { get; set; } public static void Reset() { RoleWasChecked = false; } } public sealed class IS0AUTTSTContext : IDisposable { public System.Collections.Generic.List TestRuns { get; } = [ new TestRun { ID = 1, Definition = new Definition { Application = new Application { Deleted = false } } } ]; public System.Collections.Generic.List ApplicationUsers { get; } = [ new ApplicationUser { UserID = 1, AppID = 101 } ]; public void Dispose() { } } public sealed class TestRun { public int ID { get; set; } public Definition? Definition { get; set; } } public sealed class Definition { public Application? Application { get; set; } } public sealed class Application { public bool Deleted { get; set; } } public sealed class ApplicationUser { public int UserID { get; set; } public int AppID { get; set; } } public sealed class User { public DBUser? DBUser { get; set; } public bool IsInRole(string role) { RuntimeState.RoleWasChecked = true; return role == "Basic"; } } public sealed class DBUser { public int ID { get; set; } }