Untitled Deck Flashcards

(26 cards)

1
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: The OnConfiguring method is optional in a DbContext class.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: The OnConfiguring method is typically overridden in a class that inherits from ______.

A

DbContext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which namespace must be included to use the DbContext class?

A

Microsoft.EntityFrameworkCore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What parameter does the OnConfiguring method accept?

A

DbContextOptionsBuilder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Multiple Choice: What can you configure in the OnConfiguring method? A) Logging B) Database provider C) Connection string D) All of the above

A

D) All of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What method is commonly called within OnConfiguring to set the database provider?

A

UseSqlServer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: The OnConfiguring method is called every time a new instance of DbContext is created.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the default behavior of the OnConfiguring method if not overridden?

A

It does nothing and uses the default options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Fill in the blank: You can use ______ to specify a connection string in the OnConfiguring method.

A

optionsBuilder.UseSqlServer(connectionString)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the common use case for overriding the OnConfiguring method?

A

To set up dependency injection or to provide specific configurations for different environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Multiple Choice: Which of the following is NOT a valid database provider for OnConfiguring? A) UseMySql B) UseSqlServer C) UseMongoDB D) UseSqlite

A

C) UseMongoDB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What method can be used to enable detailed error messages in OnConfiguring?

A

EnableSensitiveDataLogging

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: You can call multiple configuration methods within the OnConfiguring method.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: The OnConfiguring method can also be used to configure ______ options.

A

logging

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the effect of calling the UseLazyLoadingProxies method in OnConfiguring?

A

It enables lazy loading for navigation properties.

17
Q

Short Answer: Why might you use a connection string from a configuration file in OnConfiguring?

A

To separate configuration from code and allow for easier changes in different environments.

18
Q

What method would you use to configure a SQLite database in OnConfiguring?

19
Q

True or False: The OnConfiguring method is executed only once for the lifetime of the DbContext.

20
Q

Fill in the blank: To retrieve the connection string from the appsettings.json, you typically use ______.

A

Configuration.GetConnectionString(“DefaultConnection”)

21
Q

Which of the following is a reason to avoid hardcoding connection strings in OnConfiguring? A) Security B) Maintainability C) Flexibility D) All of the above

A

D) All of the above

22
Q

Short Answer: How can you ensure that OnConfiguring is called during dependency injection?

A

By configuring the DbContext in the Startup class.

23
Q

What is the role of the DbContextOptionsBuilder parameter in OnConfiguring?

A

It allows the configuration of the DbContext options before they are passed to the DbContext.

24
Q

True or False: You can use the OnConfiguring method to set up a connection to a remote database.

25
What method would you use to configure a PostgreSQL database in OnConfiguring?
UseNpgsql
26