All subjects.NET · 24 questions · 4 junior / 15 mid / 5 senior

Entity Framework & ADO.NET quiz and interview questions

Data access is where many .NET apps get slow or insecure. Interviews ask how Entity Framework maps classes to tables, how related data is loaded, how changes are saved — and how plain ADO.NET works underneath. Test yourself below.

Entity Framework & ADO.NET quiz24 questions in the bank · 10 per round
Level
Question type
Mode

Entity Framework & ADO.NET: key concepts

ORM and DbContext
An ORM maps tables to classes. DbContext is your session with the database: it runs queries, tracks changes and saves them with SaveChanges().
Code First and migrations
With Code First you change C# classes and generate a migration that updates the database schema step by step.
Loading related data
Eager loading (Include) loads it with the query; lazy loading loads it on first access (watch for N+1); explicit loading loads it on demand.
Change tracking
Entities loaded by a tracking query are watched; SaveChanges writes only what changed. Use AsNoTracking for read-only lists.
ADO.NET
The low-level API: SqlConnection, SqlCommand with parameters, SqlDataReader for fast forward-only reads, DataSet for disconnected data.
Safety and speed
Always use parameters (never string-concatenated SQL), dispose connections, and batch writes instead of saving inside loops.

All 24 Entity Framework & ADO.NET questions with answers

Try each one first, then open the answer. Making a class test? Use the test maker.

  1. juniorConcepts

    What is an ORM like Entity Framework?

    • A. A database server
    • B. A library that maps database tables to C# classes so you can query with LINQ
    • C. A backup tool
    • D. A web server
    Show answer

    B. A library that maps database tables to C# classes so you can query with LINQ — db.Orders.Where(o => o.Total > 100) is translated into SQL for you.

  2. juniorConcepts

    What does a DbSet<Order> represent?

    • A. One order
    • B. The Orders table you can query and add to
    • C. A database connection
    • D. A migration
    Show answer

    B. The Orders table you can query and add to — Each DbSet on your DbContext corresponds to a table (or view) of that entity type.

  3. midConcepts

    What is the Code First approach?

    • A. Writing SQL first
    • B. Defining C# entity classes first and generating the database from them via migrations
    • C. Using stored procedures only
    • D. Generating classes from an existing database
    Show answer

    B. Defining C# entity classes first and generating the database from them via migrations — Database First is the reverse: scaffold classes from an existing database.

  4. midConcepts

    What are migrations for?

    • A. Moving servers
    • B. Applying schema changes from your model to the database in versioned steps
    • C. Copying data between apps
    • D. Caching queries
    Show answer

    B. Applying schema changes from your model to the database in versioned steps — Add a property, run dotnet ef migrations add AddPhone, and apply it — the change is tracked in source control.

  5. midConcepts

    Which loading strategy loads related data in the same query using Include()?

    • A. Lazy loading
    • B. Eager loading
    • C. Explicit loading
    • D. No loading
    Show answer

    B. Eager loading — db.Orders.Include(o => o.Customer) fetches orders and customers together, avoiding N+1 queries.

  6. midConcepts

    What does SaveChanges() return?

    • A. The saved entity
    • B. The number of entries written to the database
    • C. true or false
    • D. Nothing
    Show answer

    B. The number of entries written to the database — It returns an int — the number of state entries written (inserted, updated or deleted rows).

  7. seniorFind the bug

    What is the performance problem here?

    foreach (var id in ids)
    {
        var user = db.Users.Find(id);
        user.Active = false;
        db.SaveChanges();
    }
    • A. Find is slow
    • B. SaveChanges inside the loop makes a round-trip per user — save once after the loop (or use ExecuteUpdate)
    • C. Active can't be changed
    • D. Nothing
    Show answer

    B. SaveChanges inside the loop makes a round-trip per user — save once after the loop (or use ExecuteUpdate) — Batch the work: change all entities, then call SaveChanges once. EF Core 7+ can do it in one statement with ExecuteUpdate.

  8. seniorConcepts

    What does ExecuteUpdate/ExecuteDelete (EF Core 7+) do?

    • A. Loads entities then updates them
    • B. Runs a set-based UPDATE/DELETE in the database without loading entities
    • C. Updates the schema
    • D. Deletes the database
    Show answer

    B. Runs a set-based UPDATE/DELETE in the database without loading entities — db.Users.Where(u => u.LastLogin < cutoff).ExecuteDelete() becomes one DELETE statement.

  9. juniorConcepts

    In ADO.NET, which object runs a SQL statement?

    • A. SqlConnection
    • B. SqlCommand
    • C. DataTable
    • D. SqlBulkCopy only
    Show answer

    B. SqlCommand — SqlConnection opens the connection; SqlCommand holds the SQL and parameters; a reader or Execute* method runs it.

  10. midConcepts

    SqlDataReader vs DataSet — which is true?

    • A. Both are disconnected
    • B. DataReader is fast, forward-only and connected; DataSet is an in-memory, disconnected copy
    • C. DataSet is faster
    • D. DataReader can go backwards
    Show answer

    B. DataReader is fast, forward-only and connected; DataSet is an in-memory, disconnected copy — Use a reader to stream rows quickly; DataSet/DataTable when you need to work with the data offline.

More subjects

Need software for your business instead? I'm an AI automation & full-stack developer — see what I build.

Chat on WhatsApp