ADO.NET Entity Framework Interview Questions

What is Entity Framework?
ADO.NET entity is an ORM (object relational mapping) which creates a higher abstract object model over ADO.NET components. So rather than getting into dataset, datatables, command, and connection objects as shown in the below code, you work on higher level domain objects like customers, suppliers, etc.

DataTable table = adoDs.Tables[0];
for (int j = 0; j < table.Rows.Count; j++)
    DataRow row = table.Rows[j];

    // Get the values of the fields
    string CustomerName =
    string CustomerCode =


Below is the code for Entity Framework in which we are working on higher level domain objects like customer rather than with base level ADO.NET components (like dataset, datareader, command, connection objects, etc.).

foreach (Customer objCust in obj.Customers)


Advantage of Entity Framework ?
1. EF reduce code by creating Model instead of create class to access data.
2. Easy and fast Functionality for select, Insert, update ,delete and other CRUD operation.
3. Data access code is under source control. If any Database Modification required, no need to change
    Data access logic. You have to just change  model or business object.
4. Easy to manage relationship between tables. 
5. Faster Development approach then ADO.NET.
6. Code is also usually much neater and more maintainable
7. Conceptual model can be represented in a better way.

What is pluralize and singularize in the Entity Framework dialog box?
“Pluralize” and “Singularize” give meaningful naming conventions to objects. In simple words it says do you want to represent your objects with the below naming convention:

One Customer record means “Customer” (singular).
Lot of customer records means “Customer’s” (plural, watch the “s”)

What is the importance of EDMX file in Entity Framework?

EDMX (Entity Data Model XML) is an XML file which contains all the mapping details of how your objects map with SQL tables. The EDMX file is further divided into three sections: CSDL, SSDL, and MSL.

Can you explain CSDL, SSDL and MSL sections in an EDMX file?
CSDL (Conceptual Schema definition language) is the conceptual abstraction which is exposed to the application.
SSDL (Storage Schema Definition Language) defines the mapping with your RDBMS data structure.
MSL (Mapping Schema Language) connects the CSDL and SSDL.

How can we add, update, and delete using EF?
Create the object of your entity class, add it to the data context using AddObject method, and then call the SaveChanges method.

CustomermytestEntities obj = new CustomermytestEntities();
Customer objCust = new Customer();
objCust.CustomerCode = "1001";

If you want to update, select the object, make changes to the object, and call AcceptAllChanges.

CustomermytestEntities objContext = new CustomermytestEntities();
Customer objCustomer = (Customer)objContext.Customers.FirstOrDefault();
objCustomer.CountryCode = "NEP";

If you want to delete, call the DeleteObject method as shown in the below code snippet:

CustomermytestEntities objContext = new CustomermytestEntities();
Customer objCustomer = (Customer)objContext.Customers.FirstOrDefault();


Post a Comment


ADFS (1) ADO .Net (2) Ajax (1) Angular (1) Angular Js (17) Angular2 (28) ASP .Net (14) Authentication (1) Azure (1) Breeze.js (1) C# (50) CD (1) CI (2) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DevOps (4) DI (4) Dotnet (22) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (8) Lamda (3) Linq (11) Mongodb (1) MVC (50) NodeJS (7) RDLC (1) Report (1) SDLC (1) Sql Server (30) SSIS (3) SSO (1) SSRS (2) UI (1) WCF (13) Web Api (11) Web Service (1) XMl (1)