Interview Questions.

Entity Framework Interview Questions and Answers


Entity Framework Interview Questions and Answers

Q1. What is Entity Framework in MVC?

Ans: The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping(ORM) framework that enables builders to work with relational facts as area-particular objects, casting off the want for most of the data get entry to plumbing code that developers commonly want to write.

Q2. What is the usage of Dbcontext in Entity Framework?

Ans: The magnificence that derives DbContext is called context class in entity framework.DbContext is an vital class in Entity Framework API. It is a bridge among your domain or entity instructions and the database. DbContext is the number one magnificence this is answerable for interacting with the database.

Q3. Is Entity Framework an open supply?

Ans: Entity Framework (EF) is an open source item-relational mapping (ORM)framework for ADO.NET. It become part of .NET Framework, however given that Entity framework model 6 it's far separated from .NET framework.

Q4. What is a EDMX document in Entity Framework?

Ans: An .Edmx file is an XML file that defines a conceptual model , a garage version , and the mapping between those models. An .Edmx record also incorporates facts this is utilized by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.

Q5. What are the components of Entity Framework Architecture?

Ans: Below are the additives of Entity Framework:

Entity Data Model (EDM)

LINQ to Entities

Entity SQL

Object Service

Entity Client Data Provider

ADO.Net Data Provide.

Q6. What are CSDL, SSDL and MSL sections in an EDMX record?

Ans: It is part of EDMX report which assist to engage with information base;

CSDL (Conceptual Schema Definition Language): it carries the conceptual abstraction of your database tables for you to have interaction with person, it create the cease factor for user to interact with.

SSDL (Storage Schema Definition Language): It is abstraction for data shape it is the first door by way of which database is interacting to bypass schema from database.

MSL (Mapping Schema Language) : it use to make the bridge between the CSDL and SSDL.

Q7. What is LINQ?

Ans: Language-Integrated Query (LINQ) is a manner to question records with out cumbersome stored tactics. Previously, programmers had to create stored processes and then name those stored techniques from their code. With Entity framework, you may pull records and query it the usage of language similar to SQL.

Q8. Does Entity framework help number one and foreign keys?

Ans: Yes, Entity framework supports each sorts of primary and overseas keys. You can define those in your database tables and import them on your version lessons. If you don’t already have a database installation, you can create these keys in your records version training and their respective statistics modeling instructions.

Q9. What is Entity Graph in entity framework?

Ans: Entity graph is not anything but to reveal the connection among the entities. In EDMX there we've got multiple tables and graph indicates the relation of entity as one to one, one to many or many to many relation.

Q10. What is Code first approach?

Ans: In code first approach we have the code as bunch of POCO classes however we don’t have Database.  Through the help of code best it will generate the database. You have complete control over for your code in code first method.

Q11. What are the varieties of property in Entity Framework?

Ans: We have three sorts of property in entity framework:

Scalar property

Navigation Property

Complex Property

Q12. What is lazy loading?

Ans: Lazy loading is a manner to return simplest items that are used. When you query the database model, lazy loading only returns the on the spot tables needed via the user. All associated tables are returned whilst they're used. This way you can reserve reminiscence and garage while you work with big programs. It also way that objects are created until you need them, so it makes your program faster.

Q13. How to disable the lazy loading framework?

Ans: You can disable the lazy loading by using

context.ContextOptions.LazyLoadingEnabled = false;

Q14. Difference between LINQ to SQL and Entity Framework?


Entity Framework    LINQ to SQL

It create the EDMX report to work    It create DBML report to paintings.

It paintings for any form of information base, SQL Server, DB2, My SQL and so forth.    It works for only SQL server database.

It permit to question database gadgets the usage of DBContext and  ObjectContext    It permits to question the usage of facts the usage of DataContext.

Entity Framework you may map magnificence with a couple of tables.    Classes should be one-to-one with database object with tables.

Entity frame paintings support Model first, DB first and Code first method.    It help only DB first method.

Q15.  What is keen loading?

Ans: Eager loading is the alternative of lazy loading. When you query for items, eager loading returns all of the items which include the associated items. For example, when you query a listing of customers and orders, eager loading masses all gadgets such as the clients and the orders as opposed to just what you at the beginning want (clients).

Q16. What is a navigation assets?

Ans: A navigation assets factors to related tables to your database model. For instance, when you have a consumer desk that relates to the orders desk, the navigation property points from the clients desk to the orders desk. While the primary and foreign keys are physical houses of the table, the navigation homes are a logical part of a records version. When you view the Entity framework model, you may view the navigation homes to better recognize the shape of your tables.

Q17. What is POCO magnificence in Entity Framework?

Ans: POCO stands for undeniable vintage CLR item training. If you generate the entity framework lessons POCO classes generate routinely by using gadget with more than one attributes. It’s generated based at the desk you have got inside the database. It may be most probable like underneath. It is a simple class.

HubSpot Video

Q18. How to address concurrency in Entity Framework?

Ans: There are two types of locking; Optimistic Locking and Pessimistic Locking.

Optimistic Locking: It assumes that multiple transactions will paintings with out affecting every different.  In Other phrase no locks are enforced whilst doing Optimistic locking, the transaction simply affirm that no different transition has modified the data. In case of change transaction will roll again.

Pessimistic Locking: Pessimistic locking assumes that concurrency/collision trouble will take place so a lock is placed on the information and then facts is up to date.  We can do the pessimistic locking by using specifying the Isolation degree in SQL server shop system.

In entity body paintings we will do best constructive locking. That we are able to set from EDMX Designer.

Just open the table and select any of the Row, than only set the belongings.

Q19. What are scalar and navigation homes in Entity Framework?


Scalar houses are the belongings that is at once hyperlinks with the database.

E.G. Department call, Department Id are Scalar assets.

Navigation Properties are belongings that's association with the opposite entity property.

E.G. Employees is  Navigation property.

Q20. What is customer wins and store wins mode in Entity Framework concurrency?

Ans: Client and Store wins are actions which we need to take whilst concurrency takes place. In shop Wins, statistics are loaded into entity gadgets and in Client wins facts will shop from purchaser aspect to database.