1) Explain what is ADO.NET entity framework?
ADO.NET entity framework is an ORM (Object Relational Mapping) framework developed by Microsoft. It is an extension of ADO.NET that provides an automated mechanism to access and store data in the database. With the help of ADO.NET, database can be accessed without much required programming or code.
2) Mention what is the key advantage of using Entity Framework or EF?
The main advantage of using Entity Framework or EF is that it generates code automatically for the Model (Middle Layer), Mapping code and Data Access Layer. It reduces a lot of time during the development process.
3) Mention in what all scenarios Entity Framework can be applicable?
Entity Framework can be applicable in three scenarios
- If you have existing database already or you want to build your database first than 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
4) Explain what does .edmx file contains?
.edmx file is an XML file, which declares a conceptual model, a storage model and the mapping between these models. This file also consists the information that is used by ADO.NET entity data model designer to render a model graphically. It consists of all the mapping details of how object maps with SQL tables. It is divided into three categories SSDL, CSDL, and MSL.
5) 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 which is exposed to the application
- SSDL: It stands for Storage Schema Definition Language, it defines the mapping with our RDBMS data structure
- MSL: It stands for Mapping Schema Language, it connects the SSDL and CSDL
6) Mention what is the difference between LINQ to SQL and Entity Framework?
| LINQ to SQL || Entity |
- It works only with SQL Server Database
- To maintain the relation it generates a .dbml
- It cannot generate database from model
- It permits one to one mapping between the entity classes and relational views/tables
- It enables you to query data using DataContext
- It provides tightly coupled approach
- It works with various database like DB2, MYSQL, SQL Server etc.
- It creates an .edmx files initially and relation is maintained using 3 different files .msl, .csdl and .ssdl
- It can generate database from model
- Between the entity classes and relational tables, it permits one-to-one, one-to-many and many-to-many
- It enables you to query data using EntitySQL, DBContext, and ObjectContext
- It provides loosely coupled approach
7) How can you enhance the performance of Entity Framework?
To enhance the performance of Entity Framework, you have to follow the following steps
- Try to avoid to put all the DB objects into one single entity model
- Disable change tracking for entity 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 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
8) Explain why T4 entity is important in Entity Framework?
T4 entity is important in Entity framework as it is the heart of entity framework code generation. It reads the EDMX XML file and generate C# behind code.
9) Explain how you can load related entities in EF (Entity Framework)?
You can load related entities or data in EF in three ways
- Eager Loading
- Lazy Loading
- Explicit Loading
10) 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 directly on the design surface of EDMX.
- Code Approach: For code approach we avoid working with the visual designer or entity framework.
11) Explain Lazy loading, Eager Loading, and Explicit Loading?
- Lazy Loading: It is a process to delay the loading of related objects until it is required.
- Eager Loading: It occurs when you query for an object and all of the related objects are also returned. In eager loading, related objects are loaded automatically with its parent object
- Explicit Loading: Explicitly loading takes place when you have disabled Lazy loading, and you still want to lazy loading. For this, we have to call the load method on the related entities.
12) Mention what is the difference between ADO.NET and classic ADO?
- In NET, we have data-set while ADO we have record-set
- In record-set we can only have one table and to insert more than one table you have to do inner join. While the dataset in ADO.NET can have multiple tables
- In NET, all data persist in XML while in classic ADO the data persists in binary format also
13) What is the namespace used to include .NET Data provider for SQL server in .NET code?
The namespace System.Data.SqlClient is used to include.NET data provider for SQL server in .NET code.
14) Mention what are the various methods provided by the DataSet object to generate XML?
To generate XML various DataSet object include
- ReadXml () : It reads XML document into DataSet object
- GetXml () : It returns string consisting an XML document
- Write Xml () : It writes an XML data to disk
15) Mention what is DataAdapter class in ADO.NET?
In ADO.NET data-adapter class fetch data from the database, stores data in a dataset and reflects the changes made in the dataset to the database. For all type of communication, data-adapter act as an intermediary. Using the Fill() method, data-adapter fills data to a Data-table.
16) Explain what is connected and dis-connected data access in ADO.NET?
- Connected data access: Through the DataReader objects of data-provider you can have connected data access. It provides fast access to data, and it does not allow editing.
- Dis-connected data access: Through the DataAdapter object, disconnected data access is achieved. The dataset works independently of the database, and the data is editable.