03 Data Access Layer Flashcards

(21 cards)

1
Q

What is the fundamental problem ORM tries to solve (often called the Impedance Mismatch)?

A

The mismatch between the Object-Oriented model (business entities, hierarchy) and the Relational Data model (tables, rows, flat data) .

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

What is “Shadow Information” in the context of ORM?

A

Data required for persistence (like Primary Keys, Foreign Keys, and concurrency timestamps) that has no business meaning but must be stored in the object .

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

In the Single Table inheritance mapping strategy, how are different subclasses distinguished in the database?

A

By using a “Discriminator” column (e.g., IsCustomer, IsEmployee) .

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

What is the main drawback of the Single Table inheritance strategy?

A

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) .

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

What is the Concrete Class (or “Table per Class”) inheritance mapping strategy?

A

Each non-abstract class gets its own table containing all its attributes (inherited and specific). There is no shared “Parent” table .

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

What is a major disadvantage of the Joined (Mapping all classes) inheritance strategy?

A

It requires complex queries with many JOINs to reassemble a single object, which can be slow .

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

How does the Metadata/General Scheme mapping strategy work?

A

It uses generic tables (Objects, Attributes, Values) to store data like a dictionary. It is very flexible but complex and slow .

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

How is a Many-to-Many relationship mapped in a relational database?

A

It requires a Junction Table (associative table) containing the IDs of both related entities .

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

Why is mapping an Ordered Collection (like a playlist) difficult in a database?

A

The database does not guarantee order. You must explicitly add a “SequenceID” column, making re-ordering items expensive (requires updating multiple rows) .

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

What is Pessimistic Concurrency Handling?

A

A strategy that prevents conflicts by locking records (getting exclusive access) while a user is editing .

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

What is Optimistic Concurrency Handling?

A

A strategy that allows multiple users to read, but checks a Version Number or Timestamp upon saving to ensure data hasn’t changed .

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

What happens in Optimistic Concurrency if the version number in the database differs from the version the user is saving?

A

A concurrency exception/conflict is detected, and the application must resolve it (e.g., “Last writer wins” or asking the user) .

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

What is the primary purpose of the Repository Pattern?

A

To provide a high-level abstraction for data access that behaves like an in-memory collection, decoupling Business Logic from data storage .

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

Why is the Repository Pattern useful for Unit Testing?

A

It allows developers to “mock” the database layer, so business logic can be tested without a real database connection .

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

What is a “Leaky Abstraction” in the context of Repositories?

A

When the Repository returns IQueryable, allowing the Business Logic Layer to build SQL queries, leaking database concerns into the logic .

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

What is the Unit of Work pattern typically responsible for?

A

Managing transactions (saving multiple changes at once as a single atomic operation) .

17
Q

True or False: In the Single Table strategy, modifying a property in one subclass requires changing the table structure for all subclasses.

A

True. Since they share one physical table, adding a column for one class changes the schema for all .

18
Q

True or False: Optimistic concurrency locking requires an active connection to the database while the user is editing.

A

False. That is Pessimistic locking. Optimistic is designed for disconnected scenarios (like web apps) .

19
Q

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.

A

False. The Foreign Key goes into the “Many” side’s table, pointing back to the “One” parent .

20
Q

True or False: Modern Entity Framework (EF) implementations are essentially Repositories, so wrapping them in another Repository pattern is often redundant.

A

True. DbContext is a Unit of Work and DbSet is a Repository, so adding another layer can be unnecessary .

21
Q

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.

A

False. It is better to use a dedicated “Key-Value” table to avoid redundancy and data model chaos .