Unit 5: ASP.NET Core MVC, Entity Framework Core and Security - Practice Quiz
1 What is the main purpose of the middleware request pipeline in ASP.NET Core?
2 In an ASP.NET Core application, middleware components are generally executed in what order?
3 Which middleware is commonly used to serve static files in ASP.NET Core?
4 What is custom middleware?
5 What is the main purpose of dependency injection in ASP.NET Core?
6 Where are application services commonly registered for dependency injection?
7 What is Entity Framework Core primarily used for?
8 What does ORM stand for?
9
What is the role of the DbContext class in Entity Framework Core?
10
Which property type in a DbContext usually represents a database table?
ViewDataDictionary
HttpRequest
IActionResult
DbSet<TEntity>
11 What is created first in the Entity Framework Core Code First approach?
12 Which feature is commonly used to apply Code First model changes to a database?
13 What is the starting point in the Database First approach?
14 What is commonly generated from an existing database in the Database First approach?
DbContext
15 What is the purpose of a database migration in Entity Framework Core?
16 Which command is commonly used to create a new Entity Framework Core migration?
dotnet web database open
dotnet mvc controller start
dotnet ef migrations add
dotnet core schema view
17
What does the letter C represent in CRUD?
18 Which method marks a new entity for insertion into the database?
Add
Remove
Update
Find
19 What does authentication verify?
20 What does authorization determine?
21
An ASP.NET Core application must log both the incoming request and the outgoing response status. Where should the logging middleware call await next(context)?
22 A middleware component returns a response without invoking the next middleware. What is the effect on the request pipeline?
23
An application should serve files from wwwroot without routing those requests through MVC controllers. Which built-in middleware should be added?
app.UseRouting()
app.UseAuthorization()
app.UseStaticFiles()
app.UseExceptionHandler()
24
A conventional custom middleware class receives a RequestDelegate through its constructor. Which method signature allows ASP.NET Core to execute it?
Task InvokeAsync(HttpContext context)
IResult HandleAsync(HttpResponse response)
void Configure(HttpContext context)
Task ExecuteAsync(HttpRequest request)
25 A service stores information that must be shared within one HTTP request but isolated from other requests. Which lifetime should be used?
26
A controller constructor requires IEmailSender, but no implementation has been registered. What normally happens when ASP.NET Core tries to create the controller?
27
A queried entity is modified in memory and SaveChangesAsync() is called without explicitly calling Update. Why can Entity Framework Core persist the modification?
28 The same EF Core model must run against SQL Server in production and SQLite during local testing. Which EF Core feature primarily enables this?
29
A Blog has many Post entities, and every Post has one required Blog. Which Fluent API configuration best represents this relationship?
HasMany(b => b.Posts).WithMany(p => p.Blog).IsRequired()
HasMany(b => b.Posts).WithOne(p => p.Blog).IsRequired()
HasOne(b => b.Posts).WithMany(p => p.Blog).IsRequired()
HasOne(b => b.Posts).WithOne(p => p.Blog).IsRequired()
30
An entity property must map to a database column named product_code and have a maximum length of 20. Where can both rules be configured centrally?
OnModelCreating using the Fluent API
SaveChanges using change tracking
Program.cs using endpoint routing
31
In a Code First project, a developer adds a required Email property to the Customer entity. What should normally be done to apply this model change to the database?
DbContext and rebuild the project
32
A Code First model uses a property named CustomerId in the Customer class without explicit key configuration. How does EF Core usually treat this property?
33
A team has an existing SQL Server database and needs to generate EF Core entity classes and a DbContext. Which command is appropriate?
dotnet ef migrations script
dotnet ef database update
dotnet ef migrations add
dotnet ef dbcontext scaffold
34 A developer needs to add custom behavior to a scaffolded entity while allowing the entity to be regenerated later. Which approach best protects the custom code?
35 A migration has been created locally but has not been applied or shared. The developer discovers that it is incorrect. Which command is most appropriate for removing it?
dotnet ef migrations remove
dotnet ef dbcontext optimize
dotnet ef migrations list
dotnet ef database drop
36 A production administrator needs a reviewable SQL script containing database changes between two migrations. Which command should the developer use?
dotnet ef migrations script
dotnet ef database update
dotnet ef migrations add
dotnet ef dbcontext scaffold
37 A read-only product listing loads thousands of rows and does not modify them. Which query is generally more efficient?
context.Products.UpdateRange().ToListAsync()
context.Products.RemoveRange().ToListAsync()
context.Products.AddRange().ToListAsync()
context.Products.AsNoTracking().ToListAsync()
38 A controller must delete an order only when it exists. Which sequence correctly performs the operation?
Add, then call SaveChangesAsync
Remove, then call SaveChangesAsync
AsNoTracking, then call AddRange
39 An ASP.NET Core application uses cookie authentication and protected endpoints. Which middleware order is required after routing and before endpoint execution?
UseStaticFiles() followed by UseAuthentication()
UseAuthorization() followed by UseAuthentication()
UseExceptionHandler() followed by UseAuthorization()
UseAuthentication() followed by UseAuthorization()
40
An action should be accessible only to authenticated users who satisfy a policy named CanApproveOrders. Which attribute is appropriate?
[Authorize(Policy = "CanApproveOrders")]
[ValidateAntiForgeryToken(Policy = "CanApproveOrders")]
[Authorize(Role = "CanApproveOrders")]
[AllowAnonymous(Policy = "CanApproveOrders")]
41
In an ASP.NET Core application, middleware is registered in this order: UseExceptionHandler, UseStaticFiles, UseRouting, UseAuthentication, UseAuthorization, and MapControllers. A controller throws an exception while executing an authorized action. Which component can reliably handle the exception?
UseRouting
UseStaticFiles
UseExceptionHandler
UseAuthorization
42
A middleware executes code before and after await _next(context). A later middleware short-circuits the request and never calls its own next delegate. Which behavior is expected?
43
A custom middleware needs to redirect unauthenticated requests to /login, but must allow static assets and the login endpoint through. Which placement is most appropriate?
UseStaticFiles and before UseRouting
UseExceptionHandler after the exception branch
UseStaticFiles and before endpoint execution
MapControllers and before Run
44 A custom middleware stores a request-specific correlation identifier in an instance field of the middleware class. Under concurrent requests, what is the primary defect?
HttpContext
45
A singleton service directly depends on a scoped DbContext. What is the correct assessment of this dependency graph?
46
A controller constructor requests IEnumerable<INotificationHandler>. Three handlers are registered, and one registration is repeated for the same implementation type. What does the default container normally inject?
47
An EF Core query projects entities into DTOs and uses AsNoTracking(). Later, the application modifies one projected DTO and calls SaveChanges(). What happens?
48
A LINQ query contains a custom C# method inside its Where predicate. EF Core cannot translate that method to SQL. In a modern EF Core version, what is the usual result when the query executes?
49
An entity has a property Code configured with IsRequired().HasMaxLength(20), while its database column is manually changed to allow NULL. During migration generation, what does EF Core compare?
50 A required one-to-many relationship is configured with a non-nullable foreign key, but the navigation property is not marked virtual and lazy-loading proxies are enabled. What should be expected?
51
A Code First model changes a property from string to int while existing rows contain nonnumeric values. A migration is generated successfully. When is the likely failure observed?
52
A Code First application uses a non-nullable DateTime property with no explicit database default. A new entity is inserted without setting that property. Which value is generally sent by EF Core?
NULL value despite the non-nullable property
DateTime
53 A database-first model is scaffolded, then the generated entity class is edited to add validation attributes. The database is scaffolded again. What is the main risk?
54 A database-first scaffold sees a nullable database column and generates a nullable CLR property. Application code later treats the value as non-nullable without checking it. Which issue is most likely?
NULL to zero
NOT NULL
55
Two application instances start simultaneously after a new migration has been deployed but not applied. Both call Database.Migrate(). What is the principal operational concern?
56 A migration adds a non-nullable column to a populated table without a default value. What must usually be handled for the migration to succeed?
57
Two requests load the same row with a rowversion concurrency token. Both modify it, and the first request saves successfully. What normally happens when the second request calls SaveChanges()?
DbUpdateConcurrencyException
58
A controller receives an entity graph from a client and calls Update(graph) directly. The graph omits a sensitive property that should remain unchanged. What is the major risk?
59
An ASP.NET Core application calls UseAuthorization() before UseAuthentication(). An endpoint requires an authenticated user. What is the likely consequence?
60
A policy requires claim scope=orders.read. A bearer token contains scope as the single string orders.read orders.write. A simple claim-value equality requirement is used. What is the likely result?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →