Share this:

Top 71 Frequently Asked Entity Framework Interview Questions

1. What is Entity Framework?
Answer: Entity Framework is an open-source Object-Relational Mapper (ORM) .NET application developed by Microsoft. It helps in allowing the developers for streamline mapping between various objects in software by taking the help of tables and columns.
It makes use of the objects of domain-specific classes but it does not focus on the original database tables and columns that help in storing the data. This helps in allowing the ease of work with an abstraction of a higher level while maintaining and creating the data-oriented applications.

2. List some Entity Framework pros and cons.
The pros of the Entity Framework are-

  • It has the brilliant prototypes that help in allowing writing of object-oriented codes.
  • It allows auto migrations that make setting up or modifying a database easy and timesaving.
  • It helps in shortening the codes with the help of alternate commands which helps in making the developer’s job easier and simpler.

The cons of the Entity Framework are-

  • The things can become complicated sometimes especially if the developer is not making use of the raw SQL codes.
  • Entity Framework is a slower form of Object Relational Mapper.
  • It directs the shape of the model, especially for more complex projects.

3. What is new in entity framework 7?
Answer: The new features which are included in entity framework 7 are as follows:
New platforms: .NET along with the other distinct technologies like WPF, ASP.NET, and WinForms is supported by Entity Framework 7.
Extensible and lightweight: One has the ability for extending and replacing the extensible.
Microsoft has officially ceased EDMX in Entity Framework 7.
Entity Framework 7 helps in supporting the non-relational and relational data collection.
EF7 It helps in offering a simpler SQL examination for the most usual scenarios than EF6.
Entity Framework 7 helps in permitting one for identifying added innovative keys within one’s entities in supplementation to the chief key. One has the ability of utilizing these different keys as the selection of unfamiliar key relationships.

4. How to check the installed version of Entity Framework?
Answer: To check, if you open up the reference file and detect, click the module and then inspect the runtime version numerical in the properties explorer and you can also witness the subversion. Another alternative way to check is:
Open Package Manager Consoles(PMC) in Visual Studio while typing Get-packages at the cue. The foremost line helps in portraying the Entity Framework while the list helps in portraying the version of the Entity framework that has been installed.
Hence, follow the below-mentioned steps:
Unbar the references in one’s project.
Right-click the Entity Framework.
Select property.
See the version row and then notice the updated version of the Entity Framework.

5. Describe the architecture of the Entity Framework?
Answer: The architecture of Entity Framework involves the following components which are as follows:
Entity Data Model (EDM): EDM has three parts – a conceptual model, storage model, and mapping. The conceptual model helps in including the model class along with their relationships and is independent of the database table. The storage model is a part of the database design model and helps in containing tables, stored procedures, views, relationships, and keys. Mapping refers to the information which is regarding the mapping of the conceptual model to the storage model.
LINQ to Entities (L2E): L2E is termed as the query language with which queries against the object can be written to return entities according to definitions in the conceptual model.
Entity SQL: Entity SQL is termed as an alternative query language which is more difficult than L2E.
Object Service: Object service is the entry point into the database for the access and return of the back data. It is liable for converting the returned data from an entity client data provider to an entity object structure.
Entity Client Data Provider: This layer helps in converting the LINQ-to-Entities queries to SQL queries that the database understands. It also helps in communicating with the ADO.Net data provider for sending or recovering data from the database.
Net Data Provider: This layer uses standard ADO.Net to communicate with the database.

6. How does Entity Framework work?
Answer: Entity Framework maps domain classes to the database schema translate as well as executes LINQ queries to SQL and tracks the changes in the entities. It also saves the changes to the database.

7. How to retrieve data from the database using Entity Framework in MVC?
Answer: The steps for retrieving the data are as follows-
Create a new project.

  • From Nugget package manager, add the reference of the Entity Framework.
  • Then create a new class in the model within the table structure.
  • Add connection string in the web.config.connection string name such that it matches with the context.
  • Open the Global.asax.cs classes and then add the additional namespace of Entity Framework and finally initialize the database.
  • Right-click on the Controller folder and then add a new controller and model reference in the section for the namespace.
  • Right-click on the controller name and add the sections you want to view.

8. What is Entity Data Model? How to create EDM?
Answer: Entity Data Model happens to be an expanded style of the Entity-relationship prototype which helps in stating the fundamental prototype of the data utilizing several modeling procedures. It also helps in depicting a set of fundamentals which helps in explaining the data formation disregarding its collected form. EDM is hence the connection between the database and the prototype.
For creating an Entity Data Model, one can

  • Right-click on one’s project in the Solution Explorer window.
  • Choose Add>New Item from the menu option.
  • Choose the ADO.Net Entity Data Model arrangement or template.
  • Add name and click on the Add button.

9. What is dbcontext and dbset in Entity Framework?
Answer: DbContext is defined as the class in Entity Framework API that helps in forming a connection between a domain or entity class and the database. It is primarily responsible for communicating with the database.
The DbSet is defined as another class that helps in representing an entity set for reading, creating, updating, and deleting operations.

10. What is the difference between ADO.Net and Entity Framework?
Answer: The differences between ADO.Net and Entity Framework are as follows-

  • Net helps in creating the several data layer codes that Entity Framework is not able to create.
  • Unlike ADO.Net, Entity Framework automatically helps in generating the codes for the intermediate layers, data access layers and mapping codes. This helps to cut down on development time whereas ADO.Net is not able to do this.
  • Net is faster than the Entity Framework based on performance.

11. What is LINQ?
Answer: Language-Integrated Query (LINQ) is a way to query the data without cumbersome stored procedures. Previously, programmers needed to create the stored procedures and then call these stored procedures from their code. With Entity framework, we can pull data and query it using the language which is similar to SQL.

12. Enlist the types of inheritance that are supported by Entity Framework?
Answer: There are various kinds of inheritance which have been supported by the Entity Frameworks and they are as follows:
TPT or Table per Type: This technique helps in depicting a separate or distinct table for all and every domain class.
TPC or Table per Concrete Class: This technique depicts a single table for a lone concrete class, but excluding the abstract class. So, if one inherits the abstract class in innumerable concrete classes then the features of the abstract classes become a fragment of every table of the concrete class.
Core Supporting Inheritance: For mapping, there are limited patterns of class hierarchy that may be depicted in a relational database. The most favored ones include TPT and TPH.

13. How to return multiple results set in Entity Framework?
Answer: We can use the following pattern for returning the multiple result sets:
One can make the database in the SQL Server or Local DB and occupy the tables by implementing the following script file, STOREDB.sql, utilizing SQL Server Management Studio or SSMS or Visual Studio.
Implementation of the script will be adding the 2 collected processes into the database. Choose those procedures from the functions list in the Add tab.
One can right-click on any blank portion on the Entity Framework developer and then choose the Model browser. Now alter the GetProductCM_Result to Product_SprocResult. Save the StoreDBModel.edmx file. Discover the FunctionImportMapping nodes within edmx:Mapping/../En

14. What is the difference between LINQ and Entity Framework?

LINQ Entity Framework
LINQ only operates using SQL Server Database. Entity Framework uses several databases such as SQL Server, Oracle, MYSQL, DB2, etc.
It only permits one to one mapping between relational tables and entity classes. It permits one to one, one to many & many to many mappings between entity classes and relational tables.
It maintains the relation by generating a .dbml. It first generates an .edmx file and then maintains it using 3 different files- .csdl, .msl and .ssdl.
It helps in finding the use in rapid application development along with SQL Server. It helps in finding the use in rapid application development along with SQL Server, DB2, Oracle and MySQL, etc.
You are able to query data with DataContext. You are able to query data using DbContext, EntitySQL, and ObjectContext.
It cannot support complex types. It supports complex types.
It does not create a database from the model. It can create a database from the model.

15. Explain POCO classes in Entity Framework?
Answer: POCO stands for Plain Old CLR Objects. This class of objects does not depend on any framework-specific base class, unlike a normal .NET class. They support most of the LINQ queries that Entity Object derived entities support.

16. What are various entity framework approaches?
Answer: The various approaches in Entity Framework are:

  • Database First
  • Model First
  • Code First

17. What is the code first approach in the entity framework?
Answer: Code First approach in Entity Framework helps in allowing the creation of a model and its relations with the help of classes from which the database is created. Thus, the developer has the ability to work in an object-oriented manner without having worries about the structure of the database.

18. What is the database first approach in the entity framework?
Answer: Database First approach in Entity Framework is used for making an entity model from an existing database and then decreases the amount of code that must be written.

19. What is the model first approach in the entity framework?
Answer: In the Model First approach in the Entity Framework, the model classes are created and their relationships are also created first by taking the help of the ORM. After that the physical database is generated from the model. Therefore, a diagram of entity and relations are converted into the code model.

20. Which approach is best in an entity framework?
Answer: The choice of the development approach depends on the project. If the database is present, then for the programmer the Database First approach is the best suited. If model classes and databases are not present then the programmer should go with the Model First approach. If the developer has domain classes then the Code First approach is the best choice for the programmer.

21. What is Entity Graph in an entity framework?
Answer: Entity graphs in the entity framework are used for showing the relationship between the entities. In EDMX, we are having multiple tables and graphs which help in showing the relation of an entity as one to one, one to the many, or many to many relations.

22. What is an .edmx file in the entity framework?
Answer: An .edmx file in Entity Framework is an XML file that can define conceptual models, storage models and the mapping between them. It is also having the information that the ADO.NET Entity Data Model Designer uses for rendering a model graphically.

23. What are the types of locking in entity framework?
Answer: There are various types of locking and they are as follows:
Optimistic Locking: It helps in assuming that multiple transactions will be working without affecting each other. In other words we can say that no locking is enforced while doing the Optimistic locking. The transaction just verifies that no other transition involves the modified data. In case of modification, the transaction will roll back.
Pessimistic Locking: Pessimistic locking is the locking which helps in assuming that concurrency/collision issues will be happening so a lock is placed on the records and then data is updated. We can perform the pessimistic locking by specifying the level of Isolation in SQL server stored procedure.
In entity framework we are able to do only optimistic locking.

24. What is a navigation property in the entity framework?
Answer: Navigation properties in Entity Framework are a way to represent a foreign key relationship within the database. Navigation properties help in enabling the user to describe the relationships between the entities such that they are coherent in the object-oriented language.

25. What are the types of property in Entity Framework?
Answer: Three types of property in the entity framework are as follows:

  • Scalar property
  • Navigation Property
  • Complex Property

26. What are the types of loading available in entity framework?
Answer: The types of loading that are available in the Entity Framework are-

  • Eager Loading
  • Lazy Loading
  • Explicit Loading

27. Explain Pluralize and Singularize in Entity Framework?
Answer: Pluralize and Singularize in Entity Framework helps in giving the naming conventions to the objects by making use of the plural ‘s’ for defining more than one record.

28. What is lazy loading?
Answer: Lazy loading is defined as the way for returning only the used objects. When you query the database model, lazy loading is able to return the immediate tables needed by the user. All related tables are returned when they are used. This means we are able to reserve the memory and storage when we work with large programs. It also means that the objects are created until we are having the requirement of them, so that it can make our program faster.

29. What is eager loading?
Answer: Eager loading is the opposite of lazy loading. When you query for objects, eager loading helps in the returning all the objects including the related objects. For instance, when we are querying a list of customers and orders, eager loading loads all of the objects including the customers and the orders instead of just what you originally need (customers).

30. How to disable the lazy loading framework?
Answer: We can disable the lazy loading by the context.ContextOptions.LazyLoadingEnabled = false;

31. Is Entity Framework an open source?
Answer: Yes, Entity Framework (EF) is an open source object-relational mapping (ORM) framework for the ADO.NET. It was a part of .NET Framework, but since Entity framework version 6 it is separated from .NET framework.

32. What are CSDL, SSDL and MSL sections in an EDMX file?
Answer: It is part of the EDMX file which helps in interacting with the database.
CSDL (Conceptual Schema Definition Language): It contains the conceptual abstraction of your database tables which will be interacting with the user; it helps in creating the end point for the user to interact with.
SSDL (Storage Schema Definition Language): It is defined as the abstraction for the data structure as it is the first door by which the database is interacting for passing the schema from the database.
MSL (Mapping Schema Language): It is used for making the bridge between the CSDL and SSDL.

33. What is client wins and store wins mode in Entity Framework concurrency?
Answer: Client and Store wins are the actions which are required to take when the concurrency happens. In store Wins, data gets loaded into the entity objects and in Client wins data will be stored from the client side to the database.

34. How to connect entity framework to sql server?
Answer: The entity framework can be connected to the SQL Server in the following ways:

  • A console application is to be created
  • Create a class by right clicking on the application
  • Create the variables of the class and set the required properties
  • Save the class. Add one more class in the same way
  • Right-click and create a new folder for generating the Framework Dynamic Link Library (DLL)
  • The folder can be renamed as the developer requirements
  • Save the application before adding any framework
  • Right-click the Program.cs file and select the required properties for copying the program’s address
  • Right-click on the window of the program and copy the required address for adding the DLL framework
  • After copying the address, put it in the c: drive bar and search for the folder previously added
  • After finding the folder then adding the Entity framework DLL
  • Right-clicking on the references and then adding it to browse the DLL framework
  • The application configuration file is added
  • The DB path name and database name should be declared by making use of the App. Config file
  • In the main program one must declare the context and objects
  • Press F5 to execute

35. How to prevent sql injection in entity framework?
Answer: The SQL injection is a technique for code injection that can attack data-driven applications and can destroy the database. The SQL injection is one of the most commonly used web hacking procedures that injects malicious codes in the SQL statements through the input of the web page.
LINQ helps in preventing the SQL injection in the entity framework. This takes place due to the passing of all data to the database with the help of the QL parameters. LINQ queries are not considered as susceptible to the attacks by SQL injection as they are made by implying the concatenation or manipulation of the string.

36. What are complex types in Entity Framework?
Answer: Complex types are defined as the scalar properties in the Entity Framework that consist of the different types of entities that enable the scalar elements to be organized within the required entities. Complex types in the Entity Framework do not include the keys and thus exist independently. It is not able to participate actively in the associations and does not have the navigation properties. The properties of the complex type in the Entity Framework cannot be null. Scalar properties can be null for the complex objects.
A complex type is not able to inherit anything from the other complex types. The complex type must be defined as the class in the Entity Framework. When DbContext.DetectChanges is called, Entity framework helps in detecting the changes on an object of the complex type in the members.

37. What is Dapper?
Answer: Dapper is defined as the microframework for a simple object mapper that helps in mapping the output of the native query to a domain or a c# class. Dapper is a high-performance system for accessing the data that is built by StackOverflow and which is released as an open-source. It is very easy for firing a query in SQL against the database and for mapping the result into the C# domain class.
It extends the IDbconnection interface that is available in the System.Data namespace. Dapper is the microframework which includes many methods for the extension of accessing the data and mapping the result that is defined under the class SqlMapper found under the namespace of the dapper.

38. What is fluent API in MVC?
Answer: Fluent API is a way of specifying the configuration of the model that helps in covering everything which is executed by the annotations of the data. Fluent API and data annotations could be used together, but more preference is given by the Code First to the Fluent API, then data annotations and finally to the default conventions. Fluent API is a way for configuring the domain classes.
The Fluent API of the Code First is accessed with the help of overriding the OnModelCreating method of the derived DbContext. Fluent API in the MVC is that which offers more configuration functionality than the DataAnnotations. Fluent API allows the user to configure the properties of the entities.

39. What is the proxy object?
Answer: Proxy Objects are the objects which act as an intermediary object between an accessible object and the client. Proxy Objects helps in monitoring the lifespan of the accessible objects and forwarding the calls to the objects when it is not destroyed. Proxy objects help in checking the availability of accessible objects whenever a client calls an Inaccessible property for knowing the proper information about the object.
The proxy object helps in passing the requests of the client to the accessible object. When an accessible object is not present or it is destroyed then an error is returned by the proxy object. The proxy object is the object which is always clear to the client.

40. How to turn off lazy loading in entity framework?
Answer: Lazy loading in the entity framework is the loading that can be turned off for a particular context or an entity. To turn off the lazy loading for a specific property, one must not convert it to the virtual. For disabling the lazy loading for the entire entities in a context, the configuration property must be set to false. Now let us see the ways for turning off the lazy loading.

  • Context.configuration.ProxyCreationEnabled should be true. Context.Configuration.LazyLoadingEnabled should be made true.
  • Navigation property is the property that should not be defined as virtual and public. The context will be doing the lazy loading if the property is defined as the virtual.

41. What is the use of Migrations History Table in Entity Framework?
Answer: Migration History Table is utilized by the Code First Migrations for collecting the details regarding migrations that are required for applying to the Database. By reverting, 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. In Entity Framework 5 it was a method table for the application being utilized in the Microsoft SQL Server database. However, this utilization of it has been altered in the Entity Framework 6 and Migration History Table is no more a salient system table in this.

42. How to achieve eager loading in Entity Framework?
Answer: Eager loading happens to be a procedure in the Entity Framework where a querying for a single kind of entity also charges the related entities as a fragment of the query. Eager loading can be attained by the utilization of the Include process. It depicts that appealing related data to be sent back along with query outcomes from the Database. There is only a lone communication made to the data origin, a huge amount of data is sent back in the starting query. For instance, while querying students, eager-load their registration. The pupils and their registrations will be recovered in a single query.

43. What is the importance of T4 in Entity Framework?
Answer: T4 or Text Template Transformation Toolkit happens to be a template established code generation mechanism. T4 files are the core of the Entity Framework code creation. So, the T4 code templates interpret the EDMX XML files and create a C# supporting code. This C# supporting code is termed as the one’s context classes and entity. Hence, the Entity Framework helps in aiding the manipulation and extension of the code creation and then utilizing the T4 template. Thus, the T4 template happens to be a blending of control logic and text blocks that can be created into a text file.

44. What are the advantages of Model First Approach?
Answer: The Model First Approach helps in offering the choice of creating relationships and entities directly on the developing interface off the EDMX and later one is able to execute it. It is a better natural approach for operating in comparison to the Database First Approach specifically during the development of the movement of data in the starting phases of any new project. Utilizing it, a designer helps in initiating the operation with the Model of the Database and creation of entities that helps in yielding logical sense inapt regarding their process of being stored in the Database.

45. Enlist some entity states supported in Entity Framework?
Answer: An Entity may be in one of the five states mentioned below:
Unchanged: The Entity happens to be traced by the factors and subsist in the Database. Its property is worth remaining unchanged.
Deleted: The Entity happens to be traced by the factors and subsist in the Database but remains spotted for deletion from the Database for the later period when SaveChanges is summoned.
Modified: The Entity happens to be traced by the factors and subsist in the Database and all or some of its property remains modified.
Added: The Entity framework happens to be traced by the factors but doesn’t subsist in the Database.
Detached: The Entity happens to be untraceable by the factors.

46. Explain difference between Add and AddRange?

Add AddRange
Add is used for inserting one element at a time in a collection. AddRange is used to add multiple elements.
The add method inserts the item at the end of a collection. AddRange method is used for inserting a set of records into a collection.
Add method is the method which is implemented for a new element. AddRange is employed in a collection that is already created.

47. What is a change tracker in Entity Framework?
Answer: By delinquency Entity Framework helps in tracing the alterations of the filled entities throughout the lifespan of the context. A change tracker traces alteration when one adds new records, deletes or updates the existing records. It offers all the details and information regarding updated entities being tracked by the context and all the alterations are collected by the Dbcontext level.
Hence, the change tracker helps in offering the access for altering tracking operations and information for entity instances of the context which is being traced. Instances of these classes are usually taken from the change tracker and that are not developed to be directly created in one’s application codes.

48. How can we do pessimistic locking in Entity Framework?
Answer: Pessimistic locking presumes that the collision or concurrency issues will be occurring, so a bar is set on the records and later reconditioning of the data is done. One can be executing the pessimistic locking by identifying “IsolationLevel” in SQL server collected procedures, AFO.Netlevel or via utilizing proceeding scope object.
There are four types of locks one can acquire:
Exclusive: It is used when one requires modifying data without wanting anyone else to read the proceedings.
Shared: It is used when one requires to read-only without wanting to update any distinct transactions.
Intent or demand locks: It comes into the use for utilizing to lock hierarchy.
Update lock: When one wants to update procedures or operations which move via innumerable phases before the real occurrence of updating.

49. Will There Be Any Issues Adding A Table Without Primary Keys To A Data Model?
Answer: Every entity must be having a key, even in case where the entity maps to a view. When you are using the Entity Designer for creating or updating a model, the classes that are generated inherit from EntityObject which requires EntityKey. So, we need to have a primary key in the table for adding it to the data model.

50. What Is Minimum Requirement that is needed for Entity Framework Applications for running?
Answer: The Entity Framework is defined as the component of the .NET Framework so that the Entity Framework applications may be running on any computer on which the .NET Framework starting with version 3.5 SP1 is installed.

51. What Is Csdl?
Answer: Conceptual schema definition language (CSDL) is defined as an XML-based language that helps in describing the entities, relationships and functions making up a conceptual model of a data-driven application. This conceptual model is the model that can be used by the Entity Framework or WCF Data Services.
The metadata which has been described with CSDL is used by the Entity Framework for mapping entities and relationships that are defined in a conceptual model for a data sourcing.

52. What Is Ssdl?
Answer: Store schema definition language (SSDL) is defined as an XML-based language that helps in describing the storage model of an Entity Framework application.
In an Entity Framework application, storage model metadata gets loaded from an .Ssdl file into an instance of the System.Data.Metadata.Edm.StoreItemCollection and that is accessible by making use of the methods in the System.Data.Metadata.Edm.MetadataWorkspace class. The Entity Framework makes use of the storage model metadata for translating the queries against the conceptual model for storing specific commands.

53. What Is Msl?
Answer: Mapping specification language (MSL) is defined as an XML-based language that helps in describing the mapping between the conceptual model and storage model of an Entity Framework application.
In an Entity Framework application, mapping metadata gets loaded from an .msl file at build time. The Entity Framework makes use of the mapping metadata at runtime for translating the queries against the conceptual model for storing specific commands.

54. Which Are The Key Concepts Of Entity Data Model?
Answer: The Entity Data Model (EDM) is the model which makes use of the three key concepts for describing the structure of data:
1. Entity Type: The entity type is defined as the fundamental building block which helps in describing the structure of data with the Entity Data Model. In a conceptual model, entity types are constructed by making use of the properties and describing the structure of top-level concepts, such as the customers and the orders in a business application.
2. Association Type: An association type is defined as the fundamental building block that helps in describing relationships in the Entity Data Model. In a conceptual model an association helps in representing a relationship between the two entity types.
3. Property: As an Entity Data Model the Entity types contain properties that define their structure and characteristics. For example, a Customer entity type may be having the properties such as CustomerId, Name and Address.

55. What Is Use Of Entitydatasource Control?
Answer: The ADO.NET EntityDataSource helps in controlling, supporting, data binding scenarios in the Web applications that make use of the ADO.NET Entity Framework. Like the Entity Framework, the Entitydatasource control has the availability as part of the .NET Framework 3.5, beginning with the SP1.
Like the other Web server data source controls, the EntityDataSource helps in controlling, managing, creating, reading, updating, and deleting the operations against a data source on behalf of the data-bound controls on the same page. The EntityDataSource keeps on working with the editable grids, forms with user-controlled sorting and filtering, dually bound drop-down list controls, and master-detail pages.

56. What Is a Conceptual Model?
Answer: Conceptual model is defined as the model in the entity which helps in implementing the Entity Data Model (EDM) that is specific to the Entity Framework,which helps in representing an abstract specification for the data structures defining an entity-relationship in the domain of an application.

57. What Is the Use Of Entity Container?
Answer: Entity Container helps in specifying entity sets and association sets which will be implemented in a specified namespace.

58. What Is Explicit Loading?
Answer: Explicit loading is defined as the loading that happens when objects are getting returned by a query, related objects that are not loaded at the same time. By default, the objects are not loaded until explicitly requested for using the Load method on a navigation property.

59. What Is Scalar Property?
Answer: Scalar property is defined as the property of an entity that helps in mapping to a single field in the storage model.

60. What Is Split Entity?
Answer: Split entity is defined as an entity type that is mapped for two separating types in the storage model.

61. What Do You Mean By Table-per-hierarchy?
Answer: Table-per-hierarchy is defined as a method of modeling a hierarchy in a database that includes the attributes of all the types in the hierarchy in one table.

62. What Do You Mean By Table-per-type?
Answer: Table-per-type is defined as a method of modeling a hierarchy in a database that makes use of the multiple tables with one-to-one relationships for modeling the various types.

63. What Is the Way of Loading Data in Entity Framework?
Answer: Lazy Loading: It is defined as the process that helps in loading the related objects until it is required.
Eager Loading: It is defined as the process that helps in loading the related objects and is loaded automatically with its parent object.
Explicit Loading: It is defined as the process in which the explicit loading takes place when you are having the disabled Lazy loading and you still require lazy loading. For this, we need to call the load method on the related entities.

64. Mention In What All Scenarios Entity Framework Can Be Applicable?
Answer: Entity Framework can be applicable in three scenarios

  • If you have an existing database already or you want to build your database first then other parts of the application.
  • If your prime focus is your domain classes and then create the database from your domain classes.
  • If you want to design your database schema on the visual designer and create the classes and database.

65. How Can You Enhance The Performance Of Entity Framework?

For enhancing the performance of Entity Framework, one must have to follow the following steps:

  • Try to avoid to put all the DB objects into one single entity model.
  • Disable change tracking for entities if not needed.
  • Reduce response time for the first request by using pre-generating Views.
  • If not required try to avoid fetching all the fields.
  • For data manipulation select appropriate collection.
  • Wherever needed use a compiled query.
  • Avoid using Views and Contains.
  • While binding data to grid or paging, retrieve only required no of records.
  • Debug and Optimize LINQ query

66. In what way did the Entity Framework affect the LINQ?
Answer: LINQ (Language Integrated Query) is defined as a component of Entity Framework which actually helps the programmers for querying the database without creating any stored procedures using a language which is similar to SQL.

67. What are the advantages/disadvantages of Code First Approach?

  • Based on the business objects we are capable of deciding the database structure.
  • We are also capable of deciding which classes need to be serialized and also specifying the collection to eager load.
  • Good for smaller applications.


  • All the database related stuff must be involved in the code.
  • For Stored Proms, we need to use the Fluent APIs to write it in code.
  • Not good for data intensive applications.

68. What are the advantages of Model First Approach?

  • Model first approach helps in providing the flexibility for designing the Entity Models independently and giving an option for improving at later stages.
  • Model classes are the classes that can be created by drawing it in the edmx designer, so that not much of a database is needed for it.

69. What are the advantages and disadvantages of Database First Approach?

  • It is easy for creating the entity models if there is an existing database.
  • It is the preferred approach for the data intensive applications.


  • Once we are able to create an edmx file from an existing database then the huge pile of code gets generated.
  • If we need to add additional functionality to the models generated, we are required for extending the models.

70. What is EF Data Access Architecture?
Answer: The ADO.NET Framework is the framework that supports two models of Data Access Architecture:

  • Connection Oriented
  • Disconnected

EF makes use of the disconnected model (doesn’t leave a connection open). Since you work with data and make desired changes and then you perform the SaveChanges. In N-tier applications a context either may be producing the entities or saving the entities, not both. It produces entities that get serialized and the context is disposed. Entities that return from the client application are deserialized and re-attached to a new context instance that saves their changes.

70. What are the components of Entity Framework Architecture?
Answer: Below are the components of Entity Framework:

  • Entity Data Model (EDM)
  • LINQ to Entities
  • Entity SQL
  • Object Service
  • Entity Client Data Provider
  • ADO.Net Data Provider

71. What is Optimistic locking?
Answer: Optimistic Locking is a strategy where we are capable of reading a record and taking the note of a version number (other methods to do this involving the dates, timestamps or checksums/hashes) and checking that the version hasn’t changed before we write the record back. When we write the record back then we filter the update on the version for making sure it’s atomic. (i.e. hasn’t been updated between when we are checking the version and writing the record to the disk) and updating the version in one hit.
If the record is dirty (i.e. different version to ours) then we abort the transaction and the user can restart it.
This strategy is most suitable for the high-volume systems and also for the three-tier architectures where we do not necessarily maintain a connection to the database for our session. In this situation the client cannot be able to actually maintain database locks as the connections are taken from a pool and we may not be using the same connection from one access to the next.


The above listed 71 Frequently asked Entity Framework interview questions were compiled to help freshers and experienced developers looking for a new job or job change that require Entity framework technical skills. Please go through these TOP Entity Framework interview questions and answers to get better prepared for your next job interview.

Share this: