Microsoft Entity Framework Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Microsoft Entity Framework Interview Questions & Answers

Searching for a Microsoft Entity Framework job? If you are an expert in Microsoft Entity Framework then this is for you. Do not worry, we’ve a right answer for your job interview preparation. If you are preparing for Microsoft Entity Framework job interview, we will help you in clearing the interview through Wisdomjobs interview questions and answers page. Microsoft Entity Framework is the framework that allows the .NET developers mostly to work on the databases using specific objects. Using this, the traditional way to access the data using code is eliminated. Good knowledge on Microsoft Entity Framework is required for this job. Below are the Microsoft Entity Framework interview questions and answers which makes you comfortable to face the interviews:

Microsoft Entity Framework Interview Questions

Microsoft Entity Framework Interview Questions
    1. Question 1. What Is Entity Framework?

      Answer :

      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.

    2. Question 2. Will There Be Any Issues Adding A Table Without Primary Keys To A Data Model?

      Answer :

      Every entity must have a key, even in the case where the entity maps to a view. When you use the Entity Designer to create or update a model, the classes that are generated inherit from EntityObject, which requires EntityKey. So, we have to have a primary key in the table to add it to the data model.

    3. Question 3. How Do You Truncate A Table Using Entity Data Model?

      Answer :

      Unfortunately Entity Framework doesn’t include anything straight forward to handle this. But we can still call a T-SQL statement using entity framework that will still minimizes the developers work. We can call ExecuteStoreCommand() methond on ObjectContext as shown below.

      Code:

      using (var context = new MyTestDbEntities())

      {

          context.ExecuteStoreCommand("TRUNCATE table Dummy");

      }

    4. Question 4. How Do You Query In Entity Model When The Result Has A Join From From Different Database Other Than The Entity Model?

      Answer :

      E.g.: SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1
      As the entity model doesn’t support querying from any entity other than the entities defined in Entity Data Model, we have to query aginst the data base using ExecuteStoredQuery of the context.

      Following code snippet shows how to query when other databases are joined.

      Code:

      string query = "SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1";

      using (var context = new SampleEntities())

      {

        ObjectResult records = context.ExecuteStoreQuery(query);

        foreach (DbDataRecord record in records)

        {

          //Do whatever you want

        }

      }

    5. Question 5. What Is Minimum Requirement For Entity Framework Applications To Run?

      Answer :

      The Entity Framework is a component of the .NET Framework so Entity Framework applications can run on any computer on which the .NET Framework starting with version 3.5 SP1 is installed.

    6. Question 6. What Is Csdl?

      Answer :

      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.

      The metadata that is described with CSDL is used by the Entity Framework to map entities and relationships that are defined in a conceptual model to a data source.

    7. Question 7. What Is Ssdl?

      Answer :

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

      In an Entity Framework application, storage model metadata is loaded from a .ssdl file (written in SSDL) into an instance of the System.Data.Metadata.Edm.StoreItemCollection and is accessible by using methods in the System.Data.Metadata.Edm.MetadataWorkspace class. The Entity Framework uses storage model metadata to translate queries against the conceptual model to store-specific commands.

    8. Question 8. What Is Msl?

      Answer :

      Mapping specification language (MSL) is an XML-based language that describes the mapping between the conceptual model and storage model of an Entity Framework application.

      In an Entity Framework application, mapping metadata is loaded from an .msl file (written in MSL) at build time. The Entity Framework uses mapping metadata at runtime to translate queries against the conceptual model to store-specific commands.

    9. Question 9. What Is Entity Data Model?

      Answer :

      The Entity Data Model (EDM) is a set of concepts that describe the structure of data, regardless of its stored form. The EDM borrows from the Entity-Relationship Model described by Peter Chen in 1976, but it also builds on the Entity-Relationship Model and extends its traditional uses.

      The EDM addresses the challenges that arise from having data stored in many forms. For example, consider a business that stores data in relational databases, text files, XML files, spreadsheets, and reports.

      This presents significant challenges in data modeling, application design, and data access. When designing a data-oriented application, the challenge is to write efficient and maintainable code without sacrificing efficient data access, storage, and scalability.

      When data has a relational structure, data access, storage, and scalability are very efficient, but writing efficient and maintainable code becomes more difficult. When data has an object structure, the trade-offs are reversed: Writing efficient and maintainable code comes at the cost of efficient data access, storage, and scalability. Even if the right balance between these trade-offs can be found, new challenges arise when data is moved from one form to another. The Entity Data Model addresses these challenges by describing the structure of data in terms of entities and relationships that are independent of any storage schema.

      This makes the stored form of data irrelevant to application design and development. And, because entities and relationships describe the structure of data as it is used in an application (not its stored form), they can evolve as an application evolves.

    10. Question 10. Which Are The Key Concepts Of Entity Data Model?

      Answer :

      The Entity Data Model (EDM) uses three key concepts to describe the structure of data: entity type, association type, and property. These are the most important concepts in describing the structure of data in any implementation of the EDM.

      1. Entity Type: The entity type is the fundamental building block for describing the structure of data with the Entity Data Model. In a conceptual model, entity types are constructed from properties and describe the structure of top-level concepts, such as a customers and orders in a business application.

      2. Association Type: An association type (also called an association) is the fundamental building block for describing relationships in the Entity Data Model. In a conceptual model, an association represents a relationship between two entity types (such as Customer and Order).

      3. Property: Entity types contain properties that define their structure and characteristics. For example, a Customer entity type may have properties such as CustomerId, Name, and Address.

    11. Question 11. What Is .edmx File And What It Contains?

      Answer :

      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.

    12. Question 12. How Can You Tell Ef To Have A Different Table Or Column Name Than That Defined For The Class?

      Answer :

      By convention, EF defines the table and column names based on your class and property names.
      You can use the [Table] and [Column] annotations to tell EF to use different names.

    13. Question 13. How Do You Mark A Property As Required? For Example, For A Project, The Name Is A Required Field.

      Answer :

      You use the [Required] attribute to mark a property as required.

    14. Question 14. What Is Use Of Entitydatasource Control?

      Answer :

      The ADO.NET EntityDataSource control supports data binding scenarios in Web applications that use the ADO.NET Entity Framework. Like the Entity Framework, the control is available as part of the .NET Framework 3.5, beginning with SP1.

      Like the other Web server data source controls, the EntityDataSource control manages create, read, update, and delete operations against a data source on behalf of data-bound controls on the same page. The EntityDataSource works with editable grids, forms with user-controlled sorting and filtering, dually bound drop-down list controls, and master-detail pages.

    15. Question 15. What Is Model First Approach?

      Answer :

      A new Model First approach was supported in Visual Studio 2010, which was released together with the second Entity Framework version (Entity Framework v4). In Model First approach the development starts from scratch. At first, the conceptual model is created with Entity Data Model Designer, entities and relations are added to the model, but mapping is not created.

      After this Generate Database Wizard is used to generate storage (SSDL) and mapping (MSL) parts from the conceptual part of the model and save them to the edmx file. Then the wizard generates DDL script for creating database (tables and foreign keys)

      If the model was modified, the Generate Database Wizard should be used again to keep the model and the database consistent. In such case, the generated DDL script contains DROP statements for tables, corresponding to old SSDL from the .edmx file, and CREATE statements for tables, corresponding to new SSDL, generated by the wizard from the conceptual part. In Model First approach developer should not edit storage part or customize mapping, because they will be re-generated each time when Generate Database Wizard is launched.

    16. Question 16. What Is Code First Approach?

      Answer :

      Code First allows you to define your model using C# or VB.Net classes, optionally additional configuration can be performed using attributes on your classes and properties or by using a Fluent API. Your model can be used to generate a database schema or to map to an existing database.

    17. Question 17. What Is Entity Sql?

      Answer :

      Entity SQL is a SQL-like storage-independent language, designed to query and manipulate rich object graphs of objects based on the Entity Data Model (EDM).

    18. Question 18. What Is Linq To Entities?

      Answer :

      LINQ to Entities provides Language-Integrated Query (LINQ) support for querying entities.

      LINQ to Entities enables developers to write queries against the database using one of the supported .NET Framework programming languages such as Visual Basic or Visual C#.

    19. Question 19. What Is Entityclient?

      Answer :

      System.Data.EntityClient is a storage-independent ADO.NET data provider that contains classes such as EntityConnection, EntityCommand, and EntityDataReader. Works with Entity SQL and connects to storage specific ADO.NET data providers, such as SqlClient.

    20. Question 20. What Is Deferred Loading(lazy Loading)?

      Answer :

      When objects are returned by a query, related objects are not loaded at the same time.
      Instead they are loaded automatically when the navigation property is accessed. Also known as “lazy loading,”

    21. Question 21. What Is Eager Loading?

      Answer :

      The process of loading a specific set of related objects along with the objects that were explicitly requested in the query.

    22. Question 22. What Is Complex Type?

      Answer :

      A .NET Framework class that represents a complex property as defined in the conceptual model. Complex types enable scalar properties to be organized within entities. Complex objects are instances of complex types.

    23. Question 23. What Is Conceptual Model?

      Answer :

      An implementation of the Entity Data Model (EDM), specific to the Entity Framework, which represents an abstract specification for the data structures that define an entity-relationship representation of data in the domain of an application.

    24. Question 24. What Is Use Of Entity Container?

      Answer :

      Specifies entity sets and association sets that will be implemented in a specified namespace.

    25. Question 25. What Is Explicit Loading?

      Answer :

      When objects are returned by a query, related objects are not loaded at the same time. By default, they are not loaded until explicitly requested using the Load method on a navigation property.

    26. Question 26. What Do You Mean By Navigation Property?

      Answer :

      A property of an entity type that represents a relationship to another entity type, as defined by an association. Navigation properties are used to return related objects as an EntityCollection or an EntityReference, depending on the multiplicity at the other end of the association.

    27. Question 27. What Is Scalar Property?

      Answer :

      A property of an entity that maps to a single field in the storage model.

    28. Question 28. What Is Split Entity?

      Answer :

      An entity type that is mapped to two separate types in the storage model.

    29. Question 29. What Do You Mean By Table-per-hierarchy?

      Answer :

      A method of modeling a type hierarchy in a database that includes the attributes of all the types in the hierarchy in one table.

    30. Question 30. What Do You Mean By Table-per-type?

      Answer :

      A method of modeling a type hierarchy in a database that uses multiple tables with one-to-one relationships to model the various types.

    31. Question 31. What Is Entity Graph In Entity Framework?

      Answer :

      Entity graph is nothing but to show the relationship between the entities. In EDMX there we have multiple tables and graph shows the relation of entity as one to one, one to many or many to many relation.

    32. Question 32. What Is Entity Framework Advantage?

      Answer :

      Advantage of using entity framework is to generate the automated code to interact with data base. Its make your application in fast pace of development.

    33. Question 33. Differences Between Poco, Model First And Data First Approach?

      Answer :

      Database first:

      1. Database create before generation of code.
      2. Automated code generation by visual studio.
      3. using of T4 template generate the C# code.
      4. No much control over the Code.

      Code First Approach:

      1. Database generated from POCO classes.
      2. No automated code generation.
      3. Fully control over the code. you need to write your own C# Code.

      Model First Approach:

      1. Creation of Context and tables using the Designer tool.
      2. T4 template will generate the C# code.
      3. You have not full control over the code or DB.
      4. After creation of tables, once you run application it generate database.

    34. Question 34. What Is Way Of Loading Data In Ef (entity Framework)?

      Answer :

      Lazy Loading: Process of loading the related objects until it is required.

      Eager Loading:  Process of loading the related objects is 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.

    35. Question 35. What Is Lazy Loading In Entity Framework?

      Answer :

      Lazy loading is the concept of loading the data only when we required. We can say it loading on demand. Suppose you have a Department object there you have Employee object also and there is 1 to many relation between Departments to Employee.

      But when you fetch the records of department it won't load the Employee object but the tome when you are doing the foreach on Department object Employee object not loaded but once you will do the iteration for Employee object than only the Employee object will load.

    36. Question 36. How To Disable The Lazy Loading Framework?

      Answer :

      You can disable the lazy loading by
      context.ContextOptions.LazyLoadingEnabled = false;

    37. Question 37. Can We Have Enum In Entity Framework?

      Answer :

      Yes you can create the Enum in entity framework.

    38. Question 38. What Is Client Wins And Store Wins Mode In Entity Framework Concurrency?

      Answer :

      Client and Store wins are actions which we need to take when concurrency happens. In store Wins, data are loaded into entity objects and in Client wins data will store from client side to database.

    39. Question 39. Explain What Is Ado.net Entity Framework?

      Answer :

      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.

    40. Question 40. Mention What Is The Key Advantage Of Using Entity Framework Or Ef?

      Answer :

      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.

    41. Question 41. Mention In What All Scenarios Entity Framework Can Be Applicable?

      Answer :

      Entity Framework can be applicable in three scenarios

      1. If you have existing database already or you want to build your database first than other parts of the application
      2. If your prime focus is your domain classes and then create the database from your domain classes
      3. If you want to design your database schema on the visual designer and create the classes and database

    42. Question 42. Explain What Does .edmx File Contains?

      Answer :

      .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.

    43. Question 43. Mention What Is Csdl, Ssdl And Msl Sections In An Edmx File?

      Answer :

      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

    44. Question 44. How Can You Enhance The Performance Of Entity Framework?

      Answer :

      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

    45. Question 45. Explain Why T4 Entity Is Important In Entity Framework?

      Answer :

      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.

    46. Question 46. Explain How You Can Load Related Entities In Ef (entity Framework)?

      Answer :

      You can load related entities or data in EF in three ways

      1. Eager Loading
      2. Lazy Loading
      3. Explicit Loading

    47. Question 47. Mention What Is Code First Approach And Model First Approach In Entity Framework?

      Answer :

      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.

    48. Question 48. Explain Lazy Loading, Eager Loading, And Explicit Loading?

      Answer :

      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.

    49. Question 49. Mention What Are The Various Methods Provided By The Dataset Object To Generate Xml?

      Answer :

      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

    50. Question 50. Mention What Is The Difference Between Ado.net And Classic Ado?

      Answer :

      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.

Microsoft Entity Framework Tutorial

Microsoft Entity Framework Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Microsoft Entity Framework Tutorial