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


What is Database First approach?

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.


What is Model First approach?

In Model first we create designer (model) first. If database not exist then we can create database using this designer


What is Code First approach?

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.


What are three Schema Definition Language in EDM?

SSDL (Storage Schema Definition Language)

It stores the schema of database which we created

CSDL (Conceptual Schema Definition Language)

It stores the schema of cs file which generated for each table of database. This files defines the properties created for that table and all the relationship.

ML (Mapping Language) or C-S M Mapping

It stores the mapping of SSDL and CSDL.



What is ObjectContext class in Entity Framework?

ObjectContext is the class which helps us to perform Insert, Update, Delete and create in Entity Framework.

This class is available in System.Data.Entity namespace.


Is it necessary to have EDMX file in code first approach

No, it is not necessary.

How can we specify key column in Code first approach.

By assigning a [key] attribute on property.

For Example
[Key]
public int emp_id { get; set; }



Which namespace we use in Code first approach to use [key] attribute

System.ComponentModel.DataAnnotation


How many types of loading are available in entity framework?

There are three types of loading available in entity framework:-


What is lazy loading?

Lazy loading delayed the loading of data until it is required or requested.


What is the default loading of entity framework?

Lazy loading is the default loading of entity framework.


How to turn off lazy loading in entity framework?

Set context.Configuration.LazyLoadingEnabled = false; before the query executes



What is eager loading?

Eager loading is the process where a query also loads related entities as part of the query.


How to achieve eager loading

We have to use include method to achieve eager loading


Can we execute raw sql queries in entity framework?

Yes we can.


Which function execute raw sql queries in entity framework

We use SqlQuery(“Write your sql query”) function to execute raw sql queries.



How can we make a property as required in entity framework schema?

We use [Required] attribute to mark property as required


Which namespace we use in Code first approach to use [Foreign key] attribute

System.ComponentModel.DataAnnotation.Schema


How to make changes in database using code first approach

To know the answer of this question kindly Click Here

Share your questions and topics here.