P2Pprogrammer 2 programmer


Home > Interview Question and Answer > .NET Entity Framework

ADO.NET Entity Framework (EF) Interview Question and Answer


Interview questions and Answers for .NET Entity Framework, .NET Entity Framework, LINQ, ADO.NET Entity Framework (EF) Interview Question and Answer

Interview questions and answers for Entity Framework. ADO.NET Entity Framework interview questions and answers for freshers and experienced dot net developers on Entity framework basics, architecture, Data Model, Client Data Provider, DB Context, difference between framework, LINQ & SQL etc



ADO.NET Entity Framework Interview Question and Answer


1. What is Entity Framework?

Microsoft Entity Framework (EF) is an Object Relational Mapping framework that provides an abstraction layer (a kind of mapping) between two incompatible systems (i.e. Object oriented programming languages with Relational databases). It enables us to interact with relational data in an object oriented way, meaning we can retrieve and manipulate data as strongly typed objects using LINQ queries.

2. What are the benefits of using Entity Framework?

  1. Entity Framework provides auto generated code
  2. Entity Framework reduce development time
  3. Entity Framework reduce development cost
  4. Entity Framework enables developers to visually design models and mapping of database
  5. Entity Framework provides capability of programming a conceptual model.
  6. Entity Framework provides unique syntax (LINQ / Yoda) for all object queries whether it is database or not
  7. Entity Framework allow multiple conceptual models to mapped to a single storage schema
  8. Entity Framework easy to map business objects (with drag & drop tables).

3. What is Code First approach in Entity Framework?

In Code First approach we avoid working with the Visual Designer of Entity Framework. In other words the EDMX file is excluded from the solution. So you now have complete control over the context class as well as the entity classes

4. How can we do pessimistic locking in Entity Framework?

We cannot do pessimistic locking using Entity Framework. You can invoke a stored procedure from Entity Framework and do pessimistic locking by setting the isolation level in the stored procedure. But directly, Entity Framework does not support pessimistic locking.

5. What’s the difference between LINQ to SQL and Entity Framework?

  1. LINQ to SQL is good for rapid development with SQL Server. EF is for enterprise scenarios and works with SQL Server as well as other databases.
  2. LINQ maps directly to tables. One LINQ entity class maps to one table. EF has a conceptual model and that conceptual model maps to the storage model via mappings. So one EF class can map to multiple tables, or one table can map to multiple classes.
  3. LINQ is more targeted towards rapid development while EF is for enterprise level where the need is to develop a loosely coupled framework.

6. What is the difference between DbContext and ObjectContext?

DbContext is a wrapper around ObjectContext, it’s a simplified version of ObjectContext. DbContext can be used for code first while Object Context doesn’t. It exposes the most commonly used features of ObjectContext.

7. Why do we use Lazy Loading in Entity Framework?

Entity Framework facilitates us to avoid huge, deep, highly-relational queries, so that the data will not heavy on the web.

8. What are the development approaches are supported in Entity Framework?

  1. Code First Approach – where code defines the database. Entity Framework handles creation. A complete detailed implementation of Entity Framework Code First Approach here.
  2. Database First Approach – regular approach used where database is first created or already exists.
  3. Model First Approach – where model is drawn first that further generate database scripts.

9. How we can enforce number of characters (minimum or maximum) for a field?

We can easily use property annotation of MinLength and MaxLength to enforce minimum or maximum number of characters for a specific field respectively

10. What is the query syntax we use to query an ADO.NET Entity Data Model?

We can use LINQ to Query ADO.Net Entity Framework

11. What is the role of Entity Container in Entity Framework?

Entity container is a logical grouping of entity sets, association sets, and function imports

12. What are the components of Entity Framework Architecture?

  1. Entity Data Model (EDM)
  2. LINQ to Entities
  3. Entity SQL
  4. Object Service
  5. Entity Client Data Provider
  6. ADO.Net Data Provider

13. What are the parts of Entity Data Model (EDM)?

  1. Conceptual Model
  2. Mapping
  3. Storage Model

14. What does .edmx consists of?

.edmx file is a XML file and it has Conceptual Model, Storage Model and Mapping details i.e,

  1. SSDL (Store schema definition language)
  2. CSDL (Conceptual schema definition language)
  3. MSL (Mapping specification language)

15. XXWhat is LINQ to Entities?

LINQ to Entities is a query language which we used to write queries against the object models and the query result will return the entities defined in the Conceptual Model.

16. What is Entity SQL?

Entity SQL is a query language is like LINQ to Entities. This is a bit complex compared to LINQ to Entities. A developer who is using this should learn this separately.

17. What is the role of Entity Client Data Provider?

Responsibility of Entity Client Data Provider is to convert the LINQ to Entities or Entity SQL queries to a SQL query, which is understood by the underlying database. This finally communicates with ADO.NET Data Provider which in turn used to talk to the database.

18. What is Entity Set and Association Set?

Entity Set holds the Entity Types and this most of the times compared with a database table. Association Set is used to define the relationship between Entity Sets.

19. What are the different approaches supported in the Entity Framework to create Entity Model?

  1. Database First - This approach is suitable, if we have a database already created and ready to use it. Using the existing database, we can create the Entity Models.
  2. Model First - This approach is suitable, when we prefer to create the Entity Models first and derive the database from the Entity Models
  3. Code First - This approach is suitable, when we prefer to create the Domain classes first and derive the database from the Domain classes.

20. What are the Entity States supported in Entity Framework?

Below States are supported by Entities during lifetime

  1. Added
  2. Deleted
  3. Modified
  4. Un Changed
  5. Detached

21. What is Connected Scenario in Entity Framework?

Connected Scenario is when the Entity is retrieved from the database and some operations like modification is done in the same context.

22. What is Disconnected Scenario in Entity Framework?

Disconnected Scenario is when the Entity is retrieved from the database and some operations like modification is done in the different context. In this scenario context does not understand the changes done so we have to specify the changes done outside of context.

23. What are the ways we can load the related entities in Entity Framework?

Below are the ways to load the entities in Entity Framework

  1. Lazy Loading
  2. Eager Loading
  3. Explicit Loading

24. Which type of loading is good in which scenario?

  1. Use Eager Loading, when the relations are not too much so that we can get the data in one database query.
  2. Use Eager Loading, if you are sure that we are going to use the dependent/related entities.
  3. If there are one-to-many relations use Lazy loading and if the dependent/related entities are not required down the line.
  4. When Lazy Loading is turned off, use Explicit loading when you are not sure whether dependent/related entities are not required down the line.

25. How to use Stored Procedures in Entity Framework?

Entity Framework has the ability to automatically build native commands for the database based on your LINQ-to-Entities or Entity SQL queries, as well as build the commands for inserting, updating, and deleting data. You may want to override these steps and use your own predefined stored procedures. You can use stored procedures either to get the data or to add/update/delete the records for one or multiple database tables.



Home > Interview Question and Answer > .NET Entity Framework