What is the fundamental problem ORM tries to solve (often called the Impedance Mismatch)?
The mismatch between the Object-Oriented model (business entities, hierarchy) and the Relational Data model (tables, rows, flat data) .
What is “Shadow Information” in the context of ORM?
Data required for persistence (like Primary Keys, Foreign Keys, and concurrency timestamps) that has no business meaning but must be stored in the object .
In the Single Table inheritance mapping strategy, how are different subclasses distinguished in the database?
By using a “Discriminator” column (e.g., IsCustomer, IsEmployee) .
What is the main drawback of the Single Table inheritance strategy?
It wastes storage space because attributes not relevant to a specific subclass must be stored as NULL (e.g., an Employee row has empty “Customer” columns) .
What is the Concrete Class (or “Table per Class”) inheritance mapping strategy?
Each non-abstract class gets its own table containing all its attributes (inherited and specific). There is no shared “Parent” table .
What is a major disadvantage of the Joined (Mapping all classes) inheritance strategy?
It requires complex queries with many JOINs to reassemble a single object, which can be slow .
How does the Metadata/General Scheme mapping strategy work?
It uses generic tables (Objects, Attributes, Values) to store data like a dictionary. It is very flexible but complex and slow .
How is a Many-to-Many relationship mapped in a relational database?
It requires a Junction Table (associative table) containing the IDs of both related entities .
Why is mapping an Ordered Collection (like a playlist) difficult in a database?
The database does not guarantee order. You must explicitly add a “SequenceID” column, making re-ordering items expensive (requires updating multiple rows) .
What is Pessimistic Concurrency Handling?
A strategy that prevents conflicts by locking records (getting exclusive access) while a user is editing .
What is Optimistic Concurrency Handling?
A strategy that allows multiple users to read, but checks a Version Number or Timestamp upon saving to ensure data hasn’t changed .
What happens in Optimistic Concurrency if the version number in the database differs from the version the user is saving?
A concurrency exception/conflict is detected, and the application must resolve it (e.g., “Last writer wins” or asking the user) .
What is the primary purpose of the Repository Pattern?
To provide a high-level abstraction for data access that behaves like an in-memory collection, decoupling Business Logic from data storage .
Why is the Repository Pattern useful for Unit Testing?
It allows developers to “mock” the database layer, so business logic can be tested without a real database connection .
What is a “Leaky Abstraction” in the context of Repositories?
When the Repository returns IQueryable, allowing the Business Logic Layer to build SQL queries, leaking database concerns into the logic .
What is the Unit of Work pattern typically responsible for?
Managing transactions (saving multiple changes at once as a single atomic operation) .
True or False: In the Single Table strategy, modifying a property in one subclass requires changing the table structure for all subclasses.
True. Since they share one physical table, adding a column for one class changes the schema for all .
True or False: Optimistic concurrency locking requires an active connection to the database while the user is editing.
False. That is Pessimistic locking. Optimistic is designed for disconnected scenarios (like web apps) .
True or False: A One-to-Many relationship is mapped by putting a Foreign Key in the “One” side’s table pointing to the “Many” side.
False. The Foreign Key goes into the “Many” side’s table, pointing back to the “One” parent .
True or False: Modern Entity Framework (EF) implementations are essentially Repositories, so wrapping them in another Repository pattern is often redundant.
True. DbContext is a Unit of Work and DbSet is a Repository, so adding another layer can be unnecessary .
True or False: A Class-Level Property (like a global tax rate) is best stored by adding a static column to every row in the table.
False. It is better to use a dedicated “Key-Value” table to avoid redundancy and data model chaos .