Untitled Deck Flashcards
(26 cards)
True or False: The OnConfiguring method is optional in a DbContext class.
True
Fill in the blank: The OnConfiguring method is typically overridden in a class that inherits from ______.
DbContext
Which namespace must be included to use the DbContext class?
Microsoft.EntityFrameworkCore
What parameter does the OnConfiguring method accept?
DbContextOptionsBuilder
Multiple Choice: What can you configure in the OnConfiguring method? A) Logging B) Database provider C) Connection string D) All of the above
D) All of the above
What method is commonly called within OnConfiguring to set the database provider?
UseSqlServer
True or False: The OnConfiguring method is called every time a new instance of DbContext is created.
True
What is the default behavior of the OnConfiguring method if not overridden?
It does nothing and uses the default options.
Fill in the blank: You can use ______ to specify a connection string in the OnConfiguring method.
optionsBuilder.UseSqlServer(connectionString)
What is the common use case for overriding the OnConfiguring method?
To set up dependency injection or to provide specific configurations for different environments.
Multiple Choice: Which of the following is NOT a valid database provider for OnConfiguring? A) UseMySql B) UseSqlServer C) UseMongoDB D) UseSqlite
C) UseMongoDB
What method can be used to enable detailed error messages in OnConfiguring?
EnableSensitiveDataLogging
True or False: You can call multiple configuration methods within the OnConfiguring method.
True
Fill in the blank: The OnConfiguring method can also be used to configure ______ options.
logging
What is the effect of calling the UseLazyLoadingProxies method in OnConfiguring?
It enables lazy loading for navigation properties.
Short Answer: Why might you use a connection string from a configuration file in OnConfiguring?
To separate configuration from code and allow for easier changes in different environments.
What method would you use to configure a SQLite database in OnConfiguring?
UseSqlite
True or False: The OnConfiguring method is executed only once for the lifetime of the DbContext.
False
Fill in the blank: To retrieve the connection string from the appsettings.json, you typically use ______.
Configuration.GetConnectionString(“DefaultConnection”)
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
D) All of the above
Short Answer: How can you ensure that OnConfiguring is called during dependency injection?
By configuring the DbContext in the Startup class.
What is the role of the DbContextOptionsBuilder parameter in OnConfiguring?
It allows the configuration of the DbContext options before they are passed to the DbContext.
True or False: You can use the OnConfiguring method to set up a connection to a remote database.
True