What is Entity Framework?
Entity Framework in asp.net is the enhancement of ADO.net which provides the strong mapping facilities. It is an ORM (Object Relational Mapping) which helps to interact with Relational Database using object. It provides the higher level of abstraction.
How many Type of approaches available in Entity Framework?
There are 3 approaches in Entity Framework
- Database First
- Model First
- Code First
Database First
Database first is the approach in which our database has already generated. And using this database we create our Model and code in entity framework.
Model First
In Model first we create designer (model) first. If database not exist then we can create database using this designer
Code First
In code first we create code file first and then if database not exist then database will be created automatically at runtime using this code.
What is difference between LINQ to SQL and Entity Framework?
The major difference between LINQ to SQL and Entity Framework is that LINQ to SQL support only SQL Server but Entity Framework supports almost all Relational Database.
LINQ to SQL provides limited mapping facility but entity framework provides full mapping facility.
Entity Framework Interview Questions List
- What is Entity Framework?
- What are the advantages of using Entity Framework?
- What is the Nuget Package console command to install Entity Framework, if it’s not there in you project at that time?
- Where do we use Virtual classes in Entity Framework DbContext Models?
- Entity Framework uses DbContext, How is it different from Object Context?
- What’s new in Entity Framework 6?
- Can we access a model in Entity Framework without primary key defined?
- Why do we use Lazy Loading in Entity Framework?
- Why DB Context models object disposal is important in Entity Framework?
- Can we do an insertion and deletion at the same block of code and then Apply save changes to them in a statement in Entity Framework?
- What are the development approaches are supported in Entity Framework?
- What is the query syntax we use to query an ADO.NET Entity Data Model?
- Is LINQ a feature of Entity Framework?
- Does Default New Project Creation under Internet Template Category of ASP.NET MVC have any DB Context Ready while creating the project?
- If you provide the Primary Key value while inserting record to Entity Framework, will that execute fine, or will it throw an error while the adding statement?
- What are the properties or Database Elements get copied in Dataset when Clone method is used?
- What is the role of a Self-Tracking Entities?
- Can you describe the feature of split entity in Entity Framework?
- What is the role of Entity Container in Entity Framework?
- Do we need to define any assembly refinances of entity framework if we use in web.config file?
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.
Microsoft introduced Entity Framework with .NET Framework v3.5 Service Pack 1 supporting basic Object Relational Mapping support but later EF4 was introduced as second version aligning with .NET Framework v4.0.
Back to top

Back to top
What are the advantages of using Entity Framework?
Main advantages of Entity Framework are:
- Separation of Concerns (SoC).
- LINQ is used as a common syntax for all object queries.
- Code Auto-Generation.
What is the Nuget Package console command to install Entity Framework, if it’s not there in you project at that time?
Following is the Nuget Package console command to install Entity Framework:
Where do we use Virtual classes in Entity Framework DbContext Models?
We use Virtual classes in Entity Framework in context class where we define DBSet of corresponding table. As we can see easily in below code sample for Students and Departments:

Back to top

Back to top
Entity Framework uses DbContext, How is it different from Object Context?
DbContext can be used for code first while Object Context doesn’t. It exposes the most commonly used features of ObjectContext.
Back to top
Back to top
What’s new in Entity Framework 6?
- Customizing Code First Conventions.
- Logging of database commands.
- Stored Procedure Mapping.
- Asynchronous Queries and Save support.
With EF6, in applications with lots of tables and relationships defined, our context objects open faster. We should also be better insulated from dropped connections (at least, if the drop is transient and not permanent — nothing is going to help there). EF6 also generates SQL faster from LINQ queries than before (though it’s the same SQL that’s being generated as in earlier versions of EF, so your actual data access won’t be any faster or slower).
Back to top

Back to top
Can we access a model in Entity Framework without primary key defined?
No, but we can access data.
Using Primary Key:
Student student = db.Students.Find(id);
Without Primary Key:
Student student = db.Students.Where(x=>x.StudentName==”Ahmad”);
Student student = db.Students.Find(id);
Student student = db.Students.Where(x=>x.StudentName==”Ahmad”);
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.
Why DB Context models object disposal is important in Entity Framework?
Until it’s disposed, it will be holding resources that aren’t in. If not disposed then Garbage collector will free the space but in some instance it holds up.
Can we do an insertion and deletion at the same block of code and then Apply save changes to them in a statement in Entity Framework?
Yes, WE CAN by using the below piece of code:
Here the student record will insert to db but not physically. When we call SaveChanges method then it actually insert in db and commit the transaction. If we delete before committing transaction nothing will change in database.
Back to top

Back to top
What are the development approaches are supported in Entity Framework?
- Code First Approach – where code defines the database. Entity Framework handles creation.
- 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 scripts.
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. For Example:
Is LINQ a feature of Entity Framework?
Yes, following is the example to get student record from Section A.
The same in Entity Framework:
Student student = db.Students.Where(x=>x.Section==”A”);
Back to top

Back to top
Does Default New Project Creation under Internet Template Category of ASP.NET MVC have any DB Context Ready while creating the project?
If you provide the Primary Key value while inserting record to Entity Framework, will that execute fine, or will it throw an error while the adding statement?
Yes it will threw error if same a record present with same data. If identity is set then it will give error in any case.
Back to top

Back to top
What are the properties or Database Elements get copied in Dataset when Clone method is used?
What is the role of a Self-Tracking Entities?
Can you describe the feature of split entity in Entity Framework?
Entity splitting gives us the ability to take an entity in our model and split this entity into multiple database tables. When we query an entity, Entity Framework will create a query that Automatically joins the related physical tables for us.
Back to top
Back to top
What is the role of Entity Container in Entity Framework?
Entity container is a logical grouping of entity sets, association sets, and function imports. The following must be true of an entity container defined in a conceptual model:
At least one entity container must be defined in each conceptual model. The entity container must have a unique name within each conceptual model.
Do we need to define any assembly references of entity framework if we use in web.config file?
Yes, that is necessary:

No comments:
Post a Comment