Which approach does Entity Framework use by default for mapping inheritance hierarchies?

  • Single Table Inheritance
  • Table-per-Concrete-Class (TPC)
  • Table-per-Hierarchy (TPH)
  • Table-per-Type (TPT)
Entity Framework uses Table-per-Hierarchy (TPH) inheritance by default for mapping inheritance hierarchies. This means that all types in the inheritance hierarchy are mapped to a single table in the database, with a discriminator column used to differentiate between the types. While this approach simplifies the database schema, it may lead to null values and can be less performant when dealing with complex inheritance hierarchies.

How does Entity Framework handle inheritance when using the Code-First approach?

  • Joined Table
  • Table-Per-Concrete Class (TPC)
  • Table-Per-Hierarchy (TPH)
  • Table-Per-Type (TPT)
In the Code-First approach, Entity Framework handles inheritance by defaulting to Table-Per-Hierarchy (TPH) strategy, where all classes in the inheritance hierarchy are mapped to a single table. To implement Table-Per-Concrete Class (TPC) inheritance, explicit configurations are required, specifying separate tables for each class in the hierarchy, resulting in a challenge due to maintaining relationships and ensuring data integrity across multiple tables.

In an advanced scenario, how can you customize the mapping of inheritance hierarchies beyond the default strategies provided by Entity Framework?

  • Customizing the SQL queries generated by Entity Framework
  • Extending the base DbContext class to override default behavior
  • Modifying the EDMX file directly
  • Using fluent API to configure entity mappings
In advanced scenarios, you can customize the mapping of inheritance hierarchies beyond the default strategies provided by Entity Framework using the fluent API. This allows for fine-grained control over entity mappings, including specifying table names, column names, and relationships. Modifying the EDMX file directly is not recommended as it can be complex and error-prone. Customizing SQL queries or extending the base DbContext class may not provide the same level of flexibility as using the fluent API.

What are the performance considerations when choosing between TPH, TPT, and TPC inheritance strategies in Entity Framework?

  • All three strategies have similar performance characteristics
  • TPC often leads to redundant data in multiple tables, increasing storage requirements and affecting performance
  • TPH can result in wide tables with many nullable columns, impacting storage and query performance
  • TPT requires additional joins for querying, potentially impacting performance
When choosing between TPH, TPT, and TPC inheritance strategies in Entity Framework, there are several performance considerations to keep in mind. TPH can result in wide tables with many nullable columns, which can impact storage and query performance, especially when dealing with large datasets. TPT requires additional joins for querying, potentially affecting performance, but it can provide better normalization and query performance compared to TPH in certain scenarios. TPC often leads to redundant data in multiple tables, increasing storage requirements and potentially affecting performance negatively. It's essential to analyze the specific requirements and trade-offs of each strategy to determine the most suitable one for a given scenario.

In Table-per-Type (TPT) inheritance, each type in the hierarchy is mapped to a different ________.

  • class
  • context
  • database table
  • entity set
In Table-per-Type (TPT) inheritance, each type in the hierarchy is mapped to a different database table. This means that each concrete type in the inheritance hierarchy gets its own table in the database, which can lead to a normalized database schema.

To implement a TPC inheritance strategy, you need to override the ________ method and configure the mappings.

  • OnConfiguring
  • OnModelCreating
  • OnModelCreating
  • OnModelCreating
To implement a Table-Per-Concrete (TPC) inheritance strategy in Entity Framework, you need to override the OnModelCreating method in your DbContext class and configure the mappings for each concrete type separately.

In advanced inheritance scenarios, the ________ method is used to configure specific mappings between an entity and a database table.

  • ConfigureMap
  • Map
  • MapInheritance
  • MapTo
In Entity Framework Core, the Map method is used in advanced inheritance scenarios to configure specific mappings between an entity and a database table.

In a complex model with mixed inheritance, ________ can be used to resolve ambiguity in the mapping.

  • TPC
  • TPH
  • TPT
  • TableSplitting
In Entity Framework, Table-Per-Concrete (TPC) can be used to resolve ambiguity in the mapping of a complex model with mixed inheritance.

In a scenario where an application requires polymorphic behavior, which Entity Framework inheritance strategy would be most suitable and why?

  • Joined Tables (JT): Each class in the hierarchy maps to its own database table, with a one-to-one relationship between the base class table and derived class tables.
  • Table per Concrete Type (TPC): Each class maps to its own database table, including inherited properties.
  • Table per Hierarchy (TPH): All properties from all classes are mapped to a single database table.
  • Table per Type (TPT): Each class in the hierarchy maps to its own database table.
Joined Tables (JT) strategy would be most suitable. In scenarios requiring polymorphic behavior, Joined Tables allow for efficient querying and maintainability. Each class in the hierarchy maps to its own table, with a one-to-one relationship between the base class table and derived class tables. This strategy ensures database normalization while providing flexibility and clarity in the database structure.

What is the primary use of stored procedures within Entity Framework?

  • Enforcing business logic
  • Enhancing performance and security
  • Providing a way to write complex queries
  • Simplifying database design
The primary use of stored procedures within Entity Framework is to enhance performance and security by reducing the amount of data sent between the database and the application, and by encapsulating business logic on the database server.