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?
- Entity Framework provides auto generated code
- Entity Framework reduce development time
- Entity Framework reduce development cost
- Entity Framework enables developers to visually design models and mapping of database
- Entity Framework provides capability of programming a conceptual model.
- Entity Framework provides unique syntax (LINQ / Yoda) for all object queries whether
it is database or not
- Entity Framework allow multiple conceptual models to mapped to a single storage
- 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
5. What’s the difference between LINQ to SQL and Entity Framework?
- 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.
- 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.
- 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?
- Code First Approach – where code defines the database. Entity Framework handles
creation. A complete detailed implementation of Entity Framework Code First Approach
- Database First Approach – regular approach used where database is first created
or already exists.
- Model First Approach – where model is drawn first that further generate database
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
12. What are the components of Entity Framework Architecture?
- Entity Data Model (EDM)
- LINQ to Entities
- Entity SQL
- Object Service
- Entity Client Data Provider
- ADO.Net Data Provider
13. What are the parts of Entity Data Model (EDM)?
- Conceptual Model
- Storage Model
14. What does .edmx consists of?
.edmx file is a XML file and it has Conceptual Model, Storage Model and Mapping
- SSDL (Store schema definition language)
- CSDL (Conceptual schema definition language)
- 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
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
- 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.
- Model First - This approach is suitable, when we prefer to create the Entity Models
first and derive the database from the Entity Models
- 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
- Un Changed
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
- Lazy Loading
- Eager Loading
- Explicit Loading
24. Which type of loading is good in which scenario?
- Use Eager Loading, when the relations are not too much so that we can get the data
in one database query.
- Use Eager Loading, if you are sure that we are going to use the dependent/related
- If there are one-to-many relations use Lazy loading and if the dependent/related
entities are not required down the line.
- 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
Home > Interview Question and
Answer > .NET Entity Framework