Entity Framework Core Interview

LINQ Queries, Filtering, Projection & Query Execution

Entity Framework Core interview questions covering LINQ translation, filtering, projection, pagination, joins, grouping and query execution.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
51
Mid-LevelIntermediate

How does EF Core translate LINQ into SQL?

EF Core builds an expression tree from an IQueryable LINQ query and asks the configured database provider to translate supported expressions into its query language, usually SQL. The query is normally sent only when it is enumerated or materialized.

52
Mid-LevelIntermediate

What is IQueryable in EF Core?

IQueryable<T> represents a composable query whose expression can be translated by a query provider such as EF Core. Operators added before execution can become part of the SQL sent to the database.

53
Mid-LevelIntermediate

What is the difference between IQueryable and IEnumerable in EF Core?

IQueryable represents a query that EF Core can continue translating into SQL. IEnumerable represents normal .NET enumeration semantics, usually after data has already been materialized or when execution has moved to client-side objects.

54
Mid-LevelIntermediate

What is deferred execution in EF Core?

Deferred execution means constructing an IQueryable does not usually execute the database query immediately. The query is executed when a terminal operation such as ToListAsync, FirstOrDefaultAsync, CountAsync, or enumeration requires results.

55
Mid-LevelIntermediate

What is immediate execution in an EF Core query?

Immediate execution occurs when an operation requires the query result now. Methods such as ToListAsync, ToArrayAsync, FirstAsync, SingleAsync, CountAsync, AnyAsync, and MaxAsync normally trigger database execution.

56
Mid-LevelIntermediate

How does Where work in EF Core?

Where adds a filtering predicate to the query. When the predicate can be translated, EF Core generates a corresponding SQL WHERE condition so unwanted rows are filtered by the database.

57
Mid-LevelIntermediate

How do Select and projection improve EF Core queries?

Select defines the shape of the query result. Instead of loading every column of an entity, projection can retrieve only the fields required by a page, API, or calculation.

58
Mid-LevelIntermediate

How do OrderBy and ThenBy work in EF Core?

OrderBy or OrderByDescending establishes the primary sort order. ThenBy or ThenByDescending adds secondary ordering when values in the previous sort key are equal.

59
Mid-LevelIntermediate

How do Skip and Take implement pagination in EF Core?

Skip omits a number of rows and Take limits the number returned. Together they implement offset pagination and are translated by relational providers into suitable SQL constructs.

60
Mid-LevelIntermediate

What is keyset pagination and when is it useful?

Keyset, or seek, pagination retrieves the next page relative to the last seen ordering key instead of skipping an increasing number of rows.

61
Mid-LevelIntermediate

What is the difference between FirstOrDefault and SingleOrDefault in EF Core?

FirstOrDefault returns the first matching row or the default value when no row exists. SingleOrDefault expects zero or one matching row and fails if multiple rows match.

62
Mid-LevelIntermediate

What is the difference between First and FirstOrDefault?

First expects at least one result and throws if the sequence is empty. FirstOrDefault returns the default value, usually null for a reference type, when no row matches.

63
Mid-LevelIntermediate

How do Any and Count differ in EF Core?

Any asks whether at least one matching row exists. Count calculates how many matching rows exist.

64
Mid-LevelIntermediate

How are aggregate functions used in EF Core?

LINQ aggregate operators such as Count, Sum, Average, Min, and Max can be translated into database aggregate functions.

65
Mid-LevelIntermediate

How does GroupBy work in EF Core?

GroupBy groups query rows by one or more keys. When followed by translatable aggregate operations, EF Core can commonly translate it into SQL GROUP BY.

66
Mid-LevelIntermediate

How are joins performed in EF Core LINQ?

EF Core can translate LINQ Join operations into SQL joins. However, when relationships are correctly modeled, navigation properties often provide more readable queries and allow EF Core to generate the required joins automatically.

67
Mid-LevelIntermediate

How can navigation properties be used instead of explicit joins?

When EF Core knows a relationship, a query can navigate through reference or collection properties and the provider can translate that navigation into appropriate SQL.

68
Mid-LevelIntermediate

What is SelectMany in EF Core?

SelectMany flattens nested collections into a single sequence. In EF Core it can be useful for querying child entities through a parent's collection navigation or expressing certain join-like query shapes.

69
Mid-LevelIntermediate

What is Contains in an EF Core query?

Contains can test whether a value exists in a collection or query. A local collection of identifiers is commonly translated into an SQL IN-style predicate by relational providers.

70
Mid-LevelIntermediate

How are string operations translated in EF Core queries?

Many common string operations can be translated into database expressions, but exact translation and case-sensitivity behavior depend on the provider and database collation.

71
Mid-LevelIntermediate

What is EF.Functions in EF Core?

EF.Functions exposes database-oriented functions that can participate in LINQ translation. Providers may offer functions such as LIKE operations or provider-specific extensions through this API.

72
Mid-LevelIntermediate

What is client evaluation in EF Core and why should it be treated carefully?

Client evaluation means part of a query is executed by .NET after data has been obtained rather than translated to the database. Modern EF Core restricts unsupported client evaluation in important query positions because silently downloading large tables could cause severe performance problems.

73
Mid-LevelIntermediate

How can you inspect SQL generated by EF Core?

EF Core queries can expose their generated SQL through ToQueryString for diagnostic purposes before execution. Application logging can also capture executed database commands when appropriate logging categories and levels are enabled.

74
Mid-LevelIntermediate

What are compiled queries in EF Core?

EF Core normally caches aspects of query compilation automatically, but explicit compiled queries can reduce repeated query-compilation overhead in selected hot paths.

75
Mid-LevelIntermediate

What are best practices for LINQ query performance in EF Core?

Keep filtering, sorting, aggregation, and projection on the database side whenever practical. Project only required columns, use AsNoTracking for read-only entity queries, paginate large result sets, and avoid materializing data before the database-side query is complete.