Top 50 Microsoft Entity Framework Interview Questions
Q1. How To Disable The Lazy Loading Framework?
You can disable the lazy loading via
context.ContextOptions.LazyLoadingEnabled = false;
Q2. Differences Between Poco, Model First And Data First Approach?
Database first:
@Database create earlier than technology of code.
@Automated code generation with the aid of seen studio.
@using of T4 template generate the C# code.
@No a notable deal manipulate over the Code.
Code First Approach:
@Database generated from POCO instructions.
@No automated code technology.
@Fully control over the code. You need to put in writing your very own C# Code.
Model First Approach:
@Creation of Context and tables using the Designer device.
@T4 template will generate the C# code.
@You have not whole manipulate over the code or DB.
@After advent of tables, once you run utility it generate database.
Q3. What Is Split Entity?
An entity type that is mapped to 2 separate types within the storage version.
Q4. What Is Code First Approach?
Code First permits you to define your model the usage of C# or VB.Net instructions, optionally greater configuration may be completed using attributes in your training and residences or with the useful resource of the use of a Fluent API. Your version may be used to generate a database schema or to map to an present database.
Q5. What Do You Mean By Table-consistent with-hierarchy?
A method of modeling a type hierarchy in a database that includes the attributes of all of the kinds in the hierarchy in one desk.
Q6. Mention What Is The Difference Between Ado.Internet And Classic Ado?
In NET, we've got records-set at the same time as ADO we have got record-set In record-set we will best have one desk and to insert a couple of table you want to do internal be a part of. While the dataset in ADO.NET could have more than one tables In NET, all statistics persist in XML while in traditional ADO the facts persists in binary format additionally.
Q7. What Is Explicit Loading?
When objects are again through a query, associated gadgets aren't loaded on the identical time. By default, they're no longer loaded till explicitly asked the use of the Load technique on a navigation assets.
Q8. What Is .Edmx File And What It Contains?
An .Edmx record is an XML document that defines a conceptual model, a garage model, and the mapping amongst these fashions. An .Edmx record additionally contains records this is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a version graphically.
Q9. Mention What Is The Key Advantage Of Using Entity Framework Or Ef?
The important gain of the use of Entity Framework or EF is that it generates code mechanically for the Model (Middle Layer), Mapping code and Data Access Layer. It reduces pretty a few time at some point of the development process.
Q10. What Is Way Of Loading Data In Ef (entity Framework)?
Lazy Loading: Process of loading the related gadgets till it's miles required.
Eager Loading: Process of loading the associated objects is loaded automatically with its decide object.
Explicit Loading: Explicitly loading takes vicinity if you have disabled Lazy loading, and you still need to lazy loading. For this, we've were given to name the load method at the associated entities.
Q11. What Is Entity Graph In Entity Framework?
Entity graph is nothing however to show the connection between the entities. In EDMX there we've got a couple of tables and graph shows the relation of entity as one to at least one, one to many or many to many relation.
Q12. Explain Lazy Loading, Eager Loading, And Explicit Loading?
Lazy Loading: It is a method to delay the loading of associated gadgets till it's far required.
Eager Loading: It happens while you question for an object and all of the associated gadgets also are returned. In keen loading, associated gadgets are loaded robotically with its figure object
Explicit Loading: Explicitly loading takes vicinity if you have disabled Lazy loading, and you continue to want to lazy loading. For this, we've got were given to name the burden technique at the associated entities.
Q13. What Is Entity Framework?
Entity Framework is a further layer among software and database that allows the developers to software in competition to the conceptual application version in region of programming immediately towards the relational storage schema.
Q14. How Do You Truncate A Table Using Entity Data Model?
Unfortunately Entity Framework doesn’t embody some component uncomplicated to cope with this. But we will although name a T-SQL statement the usage of entity framework with a purpose to however minimizes the builders paintings. We can call ExecuteStoreCommand() methond on ObjectContext as shown underneath.
Code:
using (var context = new MyTestDbEntities())
context.ExecuteStoreCommand("TRUNCATE table Dummy");
Q15. Can We Have Enum In Entity Framework?
Yes you could create the Enum in entity framework.
Q16. Mention In What All Scenarios Entity Framework Can Be Applicable?
Entity Framework can be relevant in 3 conditions
If you've got cutting-edge database already or you want to construct your database first than special additives of the utility
If your top recognition is your domain commands after which create the database from your area classes
If you want to design your database schema at the visual style dressmaker and create the instructions and database
Q17. What Is Ssdl?
Store schema definition language (SSDL) is an XML-based language that describes the garage version of an Entity Framework software.
In an Entity Framework software, garage version metadata is loaded from a .Ssdl record (written in SSDL) into an instance of the System.Data.Metadata.Edm.StoreItemCollection and is available through using methods inside the System.Data.Metadata.Edm.MetadataWorkspace elegance. The Entity Framework uses storage version metadata to trlate queries in competition to the conceptual version to store-unique commands.
Q18. What Is Eager Loading?
The manner of loading a selected set of associated objects together with the objects that have been explicitly asked in the question.
Q19. What Is Lazy Loading In Entity Framework?
Lazy loading is the concept of loading the data handiest while we required. We can say it loading on demand. Suppose you have got a Department item there you have got Employee item additionally and there is 1 to many relation among Departments to Employee.
But even as you fetch the information of branch it might not load the Employee object but the tome at the same time as you're doing the foreach on Department item Employee item no longer loaded however as soon as you may do the new launch for Employee item than high-quality the Employee item will load.
Q20. How Do You Query In Entity Model When The Result Has A Join From From Different Database Other Than The Entity Model?
E.G.: SELECT t1.C1, t2.C2 FROM table1 AS t1 JOIN table2 t2 ON t1.C1 = t2.C1
As the entity version doesn’t support querying from any entity other than the entities described in Entity Data Model, we have to question aginst the information base the usage of ExecuteStoredQuery of the context.
Following code snippet suggests the way to question whilst other databases are joined.
Code:
string question = "SELECT t1.C1, t2.C2 FROM table1 AS t1 JOIN table2 t2 ON t1.C1 = t2.C1";
using (var context = new SampleEntities())
ObjectResult facts = context.ExecuteStoreQuery(question);
foreach (DbDataRecord record in statistics)
//Do whatever you need
Q21. What Do You Mean By Table-in step with-type?
A method of modeling a kind hierarchy in a database that makes use of multiple tables with one-to-one relationships to model the severa sorts.
Q22. What Is Use Of Entity Container?
Specifies entity gadgets and affiliation units an amazing manner to be executed in a special namespace.
Q23. How Can You Enhance The Performance Of Entity Framework?
To beautify the general performance of Entity Framework, you need to follow the following steps
Try to avoid to place all of the DB gadgets into one unmarried entity version
Disable alternate tracking for entity if no longer wanted
Reduce response time for the number one request via the use of pre-generating Views
If now not required attempt to keep away from fetching all of the fields
For statistics manipulation select appropriate collection
Wherever wanted use compiled question
Avoid the use of Views and Contains
While binding records to grid or paging, retrieve best required no of facts
Debug and Optimize LINQ question
Q24. Explain Why T4 Entity Is Important In Entity Framework?
T4 entity is essential in Entity framework as it's far the heart of entity framework code generation. It reads the EDMX XML record and generate C# inside the lower back of code.
Q25. Will There Be Any Issues Adding A Table Without Primary Keys To A Data Model?
Every entity have to have a key, even inside the case in which the entity maps to a view. When you operate the Entity Designer to create or update a version, the training which are generated inherit from EntityObject, which requires EntityKey. So, we have to have a number one key inside the desk to feature it to the facts version.
Q26. What Is Msl?
Mapping specification language (MSL) is an XML-based totally language that describes the mapping between the conceptual model and storage version of an Entity Framework software.
In an Entity Framework software, mapping metadata is loaded from an .Msl document (written in MSL) at assemble time. The Entity Framework makes use of mapping metadata at runtime to trlate queries against the conceptual version to maintain-unique commands.
Q27. What Is Minimum Requirement For Entity Framework Applications To Run?
The Entity Framework is a part of the .NET Framework so Entity Framework programs can run on any pc on which the .NET Framework beginning with version three.5 SP1 is mounted.
Q28. What Is Entityclient?
System.Data.EntityClient is a garage-unbiased ADO.NET statistics business enterprise that carries lessons which include EntityConnection, EntityCommand, and EntityDataReader. Works with Entity SQL and connects to storage particular ADO.NET data businesses, which include SqlClient.
Q29. How Do You Mark A Property As Required? For Example, For A Project, The Name Is A Required Field.
You use the [Required] characteristic to mark a assets as required.
Q30. Explain What Does .Edmx File Contains?
.Edmx report is an XML report, which pronounces a conceptual model, a storage model and the mapping amongst those models. This report additionally consists the information this is used by ADO.NET entity data model clothier to render a model graphically. It includes all the mapping data of the way item maps with SQL tables. It is divided into three instructions SSDL, CSDL, and MSL.
Q31. Mention What Is Code First Approach And Model First Approach In Entity Framework?
In Entity Framework,
Model First Approach: In this approach we create entities, relationships without delay at the format surface of EDMX.
Code Approach: For code method we keep away from jogging with the visible dressmaker or entity framework.
Q32. What Is Linq To Entities?
LINQ to Entities gives Language-Integrated Query (LINQ) guide for querying entities.
LINQ to Entities lets in builders to jot down queries towards the database the usage of one of the supported .NET Framework programming languages together with Visual Basic or Visual C#.
Q33. What Is Deferred Loading(lazy Loading)?
When gadgets are lower again via a query, related items aren't loaded at the identical time.
Instead they'll be loaded routinely even as the navigation belongings is accessed. Also referred to as “lazy loading,”
Q34. What Is Scalar Property?
A belongings of an entity that maps to a unmarried location inside the storage version.
Q35. What Do You Mean By Navigation Property?
A assets of an entity type that represents a courting to any other entity type, as described through an association. Navigation houses are used to go back associated objects as an EntityCollection or an EntityReference, relying at the multiplicity at the alternative stop of the affiliation.
Q36. Mention What Are The Various Methods Provided By The Dataset Object To Generate Xml?
To generate XML severa DataSet object encompass
ReadXml () : It reads XML document into DataSet object
GetXml () : It returns string consisting an XML document
Write Xml () : It writes an XML facts to disk
Q37. How Can You Tell Ef To Have A Different Table Or Column Name Than That Defined For The Class?
By convention, EF defines the desk and column names based in your elegance and assets names.
You can use the [Table] and [Column] annotations to inform EF to use exceptional names.
Q38. Explain How You Can Load Related Entities In Ef (entity Framework)?
You can load related entities or information in EF in 3 strategies
Eager Loading
Lazy Loading
Explicit Loading
Q39. What Is Entity Sql?
Entity SQL is a SQL-like garage-impartial language, designed to query and manipulate wealthy item graphs of devices based totally at the Entity Data Model (EDM).
Q40. Explain What Is Ado.Internet Entity Framework?
ADO.NET entity framework is an ORM (Object Relational Mapping) framework developed by Microsoft. It is an extension of ADO.NET that gives an automated mechanism to get right of entry to and store data in the database. With the assist of ADO.NET, database can be accessed with out a splendid deal required programming or code.
Q41. What Is Entity Framework Advantage?
Advantage of using entity framework is to generate the automatic code to have interaction with statistics base. Its make your software in fast tempo of development.
Q42. What Is Client Wins And Store Wins Mode In Entity Framework Concurrency?
Client and Store wins are actions which we want to take at the same time as concurrency takes place. In shop Wins, information are loaded into entity items and in Client wins statistics will shop from customer thing to database.
Q43. What Is Model First Approach?
A new Model First approach have become supported in Visual Studio 2010, which changed into released together with the second Entity Framework model (Entity Framework v4). In Model First technique the improvement begins offevolved from scratch. At first, the conceptual version is created with Entity Data Model Designer, entities and relations are introduced to the version, but mapping isn't created.
After this Generate Database Wizard is used to generate storage (SSDL) and mapping (MSL) factors from the conceptual a part of the version and keep them to the edmx record. Then the wizard generates DDL script for growing database (tables and remote places keys)
If the model changed into changed, the Generate Database Wizard must be used all over again to keep the model and the database regular. In such case, the generated DDL script consists of DROP statements for tables, corresponding to vintage SSDL from the .Edmx report, and CREATE statements for tables, similar to new SSDL, generated by way of using the wizard from the conceptual detail. In Model First technique developer ought to no longer edit storage aspect or personalize mapping, because they'll be re-generated on every occasion even as Generate Database Wizard is released.
Q44. What Is Csdl?
Conceptual schema definition language (CSDL) is an XML-primarily based language that describes the entities, relationships, and abilities that make up a conceptual version of a statistics-driven software. This conceptual model may be utilized by the Entity Framework or WCF Data Services.
The metadata this is defined with CSDL is used by the Entity Framework to map entities and relationships which might be defined in a conceptual model to a facts deliver.
Q45. What Is Conceptual Model?
An implementation of the Entity Data Model (EDM), precise to the Entity Framework, which represents an abstract specification for the facts structures that outline an entity-courting illustration of statistics within the location of an software.
Q46. Mention What Is Csdl, Ssdl And Msl Sections In An Edmx File?
CSDL: It stands for Conceptual Schema Definition Language, it is the conceptual abstraction this is exposed to the software
SSDL: It stands for Storage Schema Definition Language, it defines the mapping with our RDBMS facts form
MSL: It stands for Mapping Schema Language, it connects the SSDL and CSDL
Q47. What Is Entity Data Model?
The Entity Data Model (EDM) is a tough and speedy of standards that describe the shape of facts, regardless of its stored form. The EDM borrows from the Entity-Relationship Model described through Peter Chen in 1976, however it moreover builds on the Entity-Relationship Model and extends its traditional makes use of.
The EDM addresses the worrying conditions that rise up from having information saved in masses of paperwork. For instance, maintain in mind a business organization that shops facts in relational databases, text documents, XML documents, spreadsheets, and critiques.
This gives widespread demanding situations in statistics modeling, application layout, and facts get right of entry to. When designing a information-orientated utility, the undertaking is to jot down green and maintainable code without sacrificing green facts get right of entry to, storage, and scalability.
When facts has a relational shape, information get right of access to, garage, and scalability are very inexperienced, however writing inexperienced and maintainable code turns into extra difficult. When facts has an object form, the change-offs are reversed: Writing efficient and maintainable code comes at the price of inexperienced information get proper of entry to, garage, and scalability. Even if the proper balance among those change-offs may be found, new demanding conditions get up while facts is moved from one shape to another. The Entity Data Model addresses those challenges by the use of describing the form of statistics in phrases of entities and relationships which might be impartial of any storage schema.
This makes the stored shape of facts irrelevant to software layout and development. And, due to the reality entities and relationships describe the structure of records as it's far utilized in an utility (now not its saved form), they are capable of evolve as an software program evolves.
Q48. What Is Use Of Entitydatasource Control?
The ADO.NET EntityDataSource manage helps records binding situations in Web programs that use the ADO.NET Entity Framework. Like the Entity Framework, the manage is available as a part of the .NET Framework 3.Five, starting with SP1.
Like the opposite Web server records supply controls, the EntityDataSource manage manages create, examine, replace, and delete operations in opposition to a facts supply on behalf of information-sure controls on the identical web page. The EntityDataSource works with editable grids, bureaucracy with person-managed sorting and filtering, dually certain drop-down listing controls, and master-element pages.
Q49. Which Are The Key Concepts Of Entity Data Model?
The Entity Data Model (EDM) uses 3 key principles to explain the form of records: entity kind, affiliation type, and property. These are the most critical concepts in describing the shape of information in any implementation of the EDM.
@Entity Type: The entity kind is the crucial constructing block for describing the structure of facts with the Entity Data Model. In a conceptual model, entity sorts are made out of residences and describe the shape of pinnacle-degree concepts, such as a clients and orders in a industrial corporation application.
@Association Type: An affiliation kind (additionally referred to as an affiliation) is the crucial building block for describing relationships inside the Entity Data Model. In a conceptual version, an association represents a relationship amongst entity sorts (at the side of Customer and Order).
@Property: Entity sorts comprise homes that outline their form and characteristics. For instance, a Customer entity type can also moreover have houses along with CustomerId, Name, and Address.
Q50. What Is Complex Type?
A .NET Framework magnificence that represents a complex assets as described inside the conceptual model. Complex kinds allow scalar homes to be organized inside entities. Complex gadgets are instances of complicated sorts.

