logo
Product
Product Tour
Aptitude Tests Coding Tests Psychometric Tests Personality Tests
Campus Hiring Features Proctoring Enterprise
Test Library Questions Pricing
Resources
Blog Case studies Books Tools
About us
Login
Log In

Search test library by skills or roles
⌘ K
logo
Assessment Platform Aptitude Tests Coding Tests Psychometric Tests Personality Tests

TRY FOR FREE

Entity Framework Interview Questions
  1. What is an SQL injection attack?
  2. How would you handle SQL injection attacks in Entity Framework?
  3. Explain POCO classes.
  4. What is the proxy object?
  5. Explain the different types of inheritance in Entity Framework.
  6. What is Code First approach in Entity Framework?
  7. What is Storage Model?
  8. What is migration in Entity Framework?
  9. What is the purpose of a DBContext class?
  10. Explain Lazy Loading.
  11. What does .edmx file contain?
  12. Explain the importance of T4 entity.
  13. What are Eager Loading and Explicit Loading?
  14. How would you handle concurrency in Entity Framework?
  15. What is Optimistic Locking?
  16. What is Pessimistic locking?
  17. What is a model in context of Entity Framework?
  18. What is dbset?
  19. What are different entity states in EF?
  20. What is the migration history table in Entity Framework?
  21. What is Complex Type in Entity Framework?
  22. Explain the ObjectSet in EF.


Interview Questions

Entity framework Interview Questions and Answers (2023)

In this post, we put together the top Entity framework interview questions and answers for beginner, intermediate and experienced candidates. These most important questions are categorized for quick browsing before the interview or to act as a detailed guide on different topics in Entity framework interviewers look for.

Entity Framework Online Test

Entity Framework Interview Questions

What is an SQL injection attack?

View answer

Hide answer

SQL injection is a code injection technique used to attack data-driven applications, and that might destroy your database. It is one of the most common web hacking techniques placing malicious code in SQL statements, via web page input.

How would you handle SQL injection attacks in Entity Framework?

View answer

Hide answer

SQL injection attacks can be performed in Entity SQL by supplying malicious input to values that are used in a query predicate and in parameter names. To avoid the risk of SQL injection, you should never combine user input with Entity SQL command text.

Entity SQL queries accept parameters everywhere that literals are accepted. You should use parameterized queries instead of injecting literals from an external agent directly into the query.

Explain POCO classes.

View answer

Hide answer

A POCO entity is a class that doesn't depend on any framework-specific base class. It is like any other normal . NET CLR class, which is why it is called "Plain Old CLR Objects". POCO entities are supported in both EF 6 and EF Core.

What is the proxy object?

View answer

Hide answer

When creating an instance of a POCO entity type, the Entity Framework creates an instance of a dynamically generated derived type that acts as a proxy for this entity. A POCO entity has some virtual properties, this proxy overrides these virtual properties of this entity to perform an action automatically when the property is accessed. This type of mechanism is used to support lay loading and the change tracking of the entity.

Explain the different types of inheritance in Entity Framework.

View answer

Hide answer

Entity Framework supports three types of inheritances:

  • Table-per-Hierarchy (TPH): The TPH inheritance states that all entities, in a hierarchy of entities, are mapped to a single table in storage schema. It means, there is only one table in database and different Entity types in Entity model that inherits from a base Entity are mapped to that table.

  • Table-per-Concrete-Type (TPC): The TPC inheritance states that each concrete class (a class which can be instantiated) in the hierarchy of entities is mapped to a separate table in storage schema. It means, there is separate table in database to maintain data for each derived entity type.

  • Table-per-Type (TPT): The TPT inheritance states that each entity in the hierarchy of entities is mapped to a separate table in storage schema. It means, there is separate table in database to maintain data for each Entity Type.

What is Code First approach in Entity Framework?

View answer

Hide answer

In the Code-First approach, you focus on the domain of your application and start creating classes for your domain entity rather than design your database first and then create the classes which match your database design.

What is Storage Model?

View answer

Hide answer

The storage model is the database design model which includes tables, views, stored procedures, and their relationships and keys.

What is migration in Entity Framework?

View answer

Hide answer

The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

At a high level, migrations work in the following way:

  • When a data model change is introduced, you can use EF Core tools to add a corresponding migration describing the updates necessary to keep the database schema in sync. EF Core compares the current model against a snapshot of the old model to determine the differences, and generates migration source files; the files can be tracked in your project's source control like any other source file.
  • Once a new migration has been generated, it can be applied to a database in various ways. EF Core records all applied migrations in a special history table, allowing it to know which migrations have been applied and which haven't.

What is the purpose of a DBContext class?

View answer

Hide answer

The class that derives DbContext is called context class in entity framework. DbContext is an important class in Entity Framework API. It is a bridge between your domain or entity classes and the database.

Explain Lazy Loading.

View answer

Hide answer

Lazy loading is the process whereby an entity or collection of entities is automatically loaded from the database the first time that a property referring to the entity/entities is accessed. Lazy loading means delaying the loading of related data, until you specifically request for it.

What does .edmx file contain?

View answer

Hide answer

An . edmx file is an XML file that defines a conceptual model , a storage model , and the mapping between these models. An . edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.

Explain the importance of T4 entity.

View answer

Hide answer

T4 entity is important in Entity framework as it is the heart of entity framework code generation. It reads the EDMX XML file and generates C# behind code.

What are Eager Loading and Explicit Loading?

View answer

Hide answer

Eager Loading: Eager Loading helps you to load all your needed entities at once; i.e., all your child entities will be loaded at single database call. This can be achieved, using the Include method, which returs the related entities as a part of the query and a large amount of data is loaded at once.

Explicit Loading: There are options to disable Lazy Loading in an Entity Framework. After turning Lazy Loading off, you can still load the entities by explicitly calling the Load method for the related entities. There are two ways to use Load method Reference (to load single navigation property) and Collection (to load collections), as shown below.

How would you handle concurrency in Entity Framework?

View answer

Hide answer

The typical approach to handle a concurrency conflict would be:

  • Catch DbUpdateConcurrencyException during SaveChanges.
  • Use DbUpdateConcurrencyException.
  • Refresh the original values of the concurrency token to reflect the current values in the database.
  • Retry the process until no conflicts occur.

What is Optimistic Locking?

View answer

Hide answer

Optimistic concurrency assumes that the update being made will be accepted, but prior to the change being made in the database, the original values of the record are compared to the existing row in the database and if any changes are detected, a concurrency exception is raised. This is useful in situations where allowing one user's changes to overwrite another's could lead to data loss.

What is Pessimistic locking?

View answer

Hide answer

If your application does need to prevent accidental data loss in concurrency scenarios, one way to do that is to use database locks. This is called pessimistic concurrency. For example, before you read a row from a database, you request a lock for read-only or for update access. If you lock a row for update access, no other users are allowed to lock the row either for read-only or update access, because they would get a copy of data that's in the process of being changed.

What is a model in context of Entity Framework?

View answer

Hide answer

Entity Framework uses EDM for all the database-related operations. Entity Data Model is a model that describes entities and the relationships between them.

What is dbset?

View answer

Hide answer

The DbSet class represents an entity set that can be used for create, read, update, and delete operations. The context class (derived from DbContext ) must include the DbSet type properties for the entities which map to database tables and views.

What are different entity states in EF?

View answer

Hide answer

The Entity state represents the state of an entity. An entity is always in any one of the following states.

  • Added: The entity is marked as added.
  • Deleted: The entity is marked as deleted.
  • Modified: The entity has been modified.
  • Unchanged: The entity hasn’t been modified
  • Detached: The entity isn’t tracked.

What is the migration history table in Entity Framework?

View answer

Hide answer

Migration History Table is utilized by Code First Migrations to collect details regarding migrations that are required to apply to the Database. By revert, the denomination of the table within the Database happens to be _MigrationHistory and it is made during the application of the first migration to the Database.

What is Complex Type in Entity Framework?

View answer

Hide answer

Complex types are non-scalar properties of entity types that enable scalar properties to be organized within entities. Like entities, complex types consist of scalar properties or other complex type properties.

Explain the ObjectSet in EF.

View answer

Hide answer

The ObjectSetclass allows you to operate on a typed entity set without having to specify the entity set name as an argument to each method call. The ObjectSetclass extends the functionality of the ObjectQueryclass to provide object context functionality, such as adding and deleting objects, in the context of a typed entity set that is accessed from the ObjectContext.

Other Interview Questions

ReactJS

Business Analyst

Android

Javascript

Power BI Django .NET Core
Java 8 R PostgreSQL
Spring Boot Drupal TestNG
Check Other Interview Questions
Join 1200+ companies in 75+ countries.
Try the most candidate friendly skills assessment tool today.
GET STARTED FOR FREE
40 min tests.
No trick questions.
Accurate shortlisting.

[email protected]

Product
  • Product Tour
  • Pricing
  • Features
  • Integrations
Usecases
  • Aptitude Tests
  • Coding Tests
  • Psychometric Tests
  • Personality Tests
Helpful Content
  • 52 pre-employment tools compared
  • Compare Adaface
  • Compare Codility vs Adaface
  • Compare HackerRank vs Adaface
  • Compare Mettl vs Adaface
BOOKS & TOOLS
  • Guide to pre-employment tests
  • Check out all tools
Company
  • About Us
  • Join Us
  • Blog
Locations
  • Singapore (HQ)

    32 Carpenter Street, Singapore 059911

    Contact: +65 9447 0488

  • India

    WeWork Prestige Atlanta, 80 Feet Main Road, Koramangala 1A Block, Bengaluru, Karnataka, 560034

    Contact: +91 6305713227

© 2022 Adaface Pte. Ltd.
Terms Privacy Trust Guide

🌎 Pick your language

English Norsk Dansk Deutsche Nederlands Svenska Français Español Chinese (简体中文) Italiano Japanese (日本語) Polskie Português Russian (русский)
Search 500+ tests by skill or role name