Entity Framework Interview Questions

What is Entity Framework?
Entity Framework is an additional layer between application and database that enables the developers to program against the conceptual application model instead of programming directly against the relational storage schema.  The goal is to decrease the amount of code and maintenance required for data-oriented applications.

What is CSDL?
Conceptual schema definition language (CSDL) is an XML-based language that describes the entities, relationships, and functions that make up a conceptual model of a data-driven application. This conceptual model can be used by the Entity Framework or WCF Data Services.

What is SSDL?
Store schema definition language (SSDL) is an XML-based language that describes the storage model of an Entity Framework application.

What is .edmx file and what it contains?
An .edmx file is an XML file that defines a conceptual model, a storage model, and the mapping between these models. An .edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.

What is Code First Approach?
in this Approach we dont need to create a Database and Table First. we dont need to add edmx File in project. Code First allows you to define your model using C# classes and Your model can be used to generate a database schema or to map to an existing database.

What is LINQ To Entities?
LINQ to Entities provides Language-Integrated Query (LINQ) support for querying entities.

What is Deferred Loading(Lazy Loading)?
When objects are returned by a query, related objects are not loaded at the same time.

What is Mapping in Entity Framework?
Mapping consist information about how your conceptual model is mapped to storage model

What is Conceptual Model?
Conceptual model is your model classes and their relationships. This will be independent from your database table design.
What is Storage Model?Storage model is your database design model which includes tables, views, stored procedures and their relationships and keys.

What are Complex Types?
Complex types are a way to encapsulate a set of entity’s properties inside a structure which isn’t an entity. You use them to organize properties into structures that make your design more understandable. For example, you can have a Customer entity which has properties that make an address.
You can arrange these properties in a Address complex type. Complex types are a conceptual entities types.


What are context class?
The context class is responsible for managing  the entity objects during run time, which includes populating objects with data from a database, change tracking, and persisting data to the database.

public class ProductContext : DbContext
{
    public DbSet<CategoryCategories { getset; }
    public DbSet<ProductProducts { getset; }
}

Difference between DBContext vs ObjectContexts
ObjectContext is only useful in Model First and Database First approach. You should use DBContext if you use Entity Framework 4.1 and above.

DBSet class represents an entity set that is use for create, read, update, and delete operations.

POCOS(Plain old CLR objects) are simply entities of your Domain. Normally when we use entity framework the entities are generated automatically for you. POCO allows you to write your own entity classes. POCOS are simple entities without any data access functionality but still gives the capabilities all EntityObject functionalities like
  1. Lazy loading
  2. Change tracking
Read More about POCO Click here

Change tracking is a central concept for every Object-Relational Mapper, including Entity Framework. In an Entity Framework application, an object context is responsible for tracking changes in the entities. When doing updates to objects the normal work flow with Entity Framework has three steps.

1.       Retrieve data from the database.
2.       Update some properties on some objects.
3.       Save the updates to the database

Advantages of Entity Framework
  1. It provides auto generated code
  2. It reduce development time
  3. It reduce development cost
  4. It enables developers to visually design models and mapping of database
  5. It provides capability of programming a conceptual model.
  6. It provides unique syntax (LINQ / Yoda) for all object queries whether it is database or not
  7. It allow multiple conceptual models to mapped to a single storage schema
  8. It’s easy to map business objects (with drag & drop tables).
Disadvantages of Entity Framework:
  1. Lazy loading is the main drawbacks of EF
  2. Its syntax is complicated
  3. Its logical schema is not able to understand business entities and relation among each other
  4. Logical schema of database is not capable of using certain parts of application
  5. It is not available for every RDMS
  6. Need to handle data in nontraditional way
  7. It does not work if we change any schema of the database. We need to update the schema on the solution.
  8. It is not good for huge domain model.

to read more about Entity Framework Click @ me!

0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (43) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (47) CD (1) CI (2) CloudComputing (2) Coding (7) CQRS (1) CSS (2) Design_Pattern (6) DevOps (4) DI (3) Dotnet (8) DotnetCore (16) Entity Framework (2) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) Lamda (3) Linq (11) microservice (3) Mongodb (1) MVC (46) NodeJS (8) React (11) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (1) UI (1) UnitTest (1) WCF (14) Web Api (15) Web Service (1) XMl (1)

Dotnet Guru Archives