{
"iq":[{"id":"1",
"q":"1) What is Entity Framework?",
"answer":"Entity Framework is an ORM from Microsoft that will enable the developers to work with domain specific objects, which eliminates the extra code being written in the data access layer. "
},
{"id":"2",
"q":"2) Why to use Entity Framework? ",
"answer":"Writing ADO.NET code and managing it is a tedious job. To avoid this, Microsoft has provided a solution - Entity Framework. Entity Framework reduces a great deal of code by enabling to work with relational data as domain specific objects. "
},
{"id":"3",
"q":"3) What is the difference between Entity Framework and ADO.NET?",
"answer":" ADO.NET:-\n1) ADO.NET is faster.\n2) We need to write so much code to talk to database.\n3) Performance is better than Entity Framework.\n\nEntity Framework:-\n1) Entity Framework will be around the ADO.NET, which means ADO.NET is faster than Entity Framework.\n2)Easy to use. As an Entity Framework will talk to database without much code involved.\n3)Performance is not good compared to ADO.NET."
},
{"id":"4",
"q":" 4) What is the difference between Entity Framework and LINQ to SQL?",
"answer":"LINQ to SQL\n1) Supports only for SQL database.\n2) Allows only one-to-one mapping between the entity classes and the relational tables.\n3)dbml file is generated for maintaining the relationships.\n4)No Support for Complex Types\n5)Supports Rapid application development with SQL Server.\n\nEntity Framework\n1) Supports databases like SQL, MySQL, DB2 etc.\n2) Allows one-to-one, one-to-many & many-to-many mappings between the Entity classes and the relational tables.\n3) Relationships are maintained in 3 different files - .csdl, .msl and .ssdl\n4)Supports Complex Types\n5) Supports Rapid application development with SQL Server, DB2, MySQL etc."
},
{"id":"5",
"q":"5) What are the components of Entity Framework Architecture? ",
"answer":"\nBelow are the components of Entity Framework –\nEntity Data Model (EDM)\nLINQ to Entities\nEntity SQL\nObject Service\nEntity Client Data Provider\nADO.Net Data Provider"
},
{"id":"6",
"q":"6) What are the parts of Entity Data Model (EDM)?",
"answer":"\nBelow are the parts of Entity Data Model –\nConceptual Model\nMapping\nStorage Model"
},
{"id":"7",
"q":"7) How to create Entity Data Model (EDM)?",
"answer":" Add New Item -> ADO.NET Entity Data Model, which generates file with .edmx extension. "
},
{"id":"8",
"q":"8) What does .edmx consists of?",
"answer":".edmx file is a XML file and it has Conceptual Model, Storage Model and Mapping details i.e,\nSSDL (Store schema definition language)\nCSDL (Conceptual schema definition language)\nMSL (Mapping specification language)"
},
{"id":"9",
"q":"9) What is Conceptual Model? ",
"answer":"Conceptual Models are the model classes which contain the relationships. These are independent of the database design."
},
{"id":"10",
"q":"10) What is Storage Model?",
"answer":"Storage Models are our database design models, which contains database tables, views, stored procs and keys with relationships."
},
{"id":"11",
"q":"11) What is Mapping?",
"answer":"The Mapping will have the information on how the Conceptual Models are mapped to Storage Models."
},
{"id":"12",
"q":" 12) What is LINQ to Entities?",
"answer":"LINQ to Entities is a query language which we used to write queries against the object models and the query result will return the entities defined in the Conceptual Model."
},
{"id":"13",
"q":"13) What is Entity SQL?",
"answer":"Entity SQL is a query language is like LINQ to Entities. This is a bit complex compared to LINQ to Entities. A developer who is using this should learn this separately."
},
{"id":"14",
"q":"14) What is the role of Entity Client Data Provider?",
"answer":"Responsibility of Entity Client Data Provider is to convert the LINQ to Entities or Entity SQL queries to a SQL query, which is understood by the underlying database. This finally communicates with ADO.NET Data Provider which in turn used to talk to the database."
},
{"id":"15",
"q":" 15) What is the meaning of Pluralize and Singularize in Entity Framework?",
"answer":" Pluralize and Singularize gives the meaningful naming conventions for objects.\nWe will get this option while adding an edmx file. On selecting this option Entity Framework will adhere to Singular or Plural coding conventions. "
},
{"id":"16",
"q":"16) What is DB Context ? ",
"answer":"When we create a edmx file, it will have the list of entities and context class which will be derived from DB Context class. "
},
{"id":"17",
"q":"17) What is the role of DB Context?",
"answer":"DBContext will be responsible for Insert, Update and Delete functionalities of the entities. It acts like a bridge between the database and entity classes. "
},
{"id":"18",
"q":" 18) What is Object Context? ",
"answer":"Object Context manages all the database operations, like database connection, and manages various entities of the Entity Model. DB Context is a wrapper around Object Context."},
{"id":"19",
"q":"19) What is the difference between ObjectContext and DbContext?",
"answer":"Conceptually, both these are here for the same reason.\nDBContext is wrapper around Object Context.\nPrior to EF 4.1, EDM used to use Object Context as base class for Context classes.\nThere were some difficulties been observed in Object Context so now Db Context is introduced in EF 6.0 and this is used for all the development models –\nDatabase First, Model First and Code First.\nObject Context supports complied queries, but DB Context not.\nObject Context supports self-tracking entities, but DB Context does not.\nDB Context is thread safe, but Object Context not. "
},
{"id":"20",
"q":"20) What is Entity Set?",
"answer":"Entity Set holds the Entity Types and this most of the times compared with a database table. "
},
{"id":"21",
"q":"21) What is Association Set?",
"answer":"Association Set is used to define the relationship between Entity Sets. "
},
{"id":"22",
"q":"22) What is Entity Container? ",
"answer":" It is a wrapper for Association Sets and Entity Sets and this is a critical to query a model. "
},
{"id":"23",
"q":"23) What is Entity Graph?",
"answer":" Entity Graph is when one entity has a relation with other entity."
},{"id":"24",
"q":" 24) What is T4 Templates? ",
"answer":"T4 Template (Text Template Transformation Toolkit) will generate the C# code based on edmx XML file. (.tt extension)"
},{"id":"25",
"q":"25) What are the types of Entities in Entity Framework? ",
"answer":"\nPOCO Entity\nDynamic Proxy"
},{"id":"26",
"q":"26) What is POCO Entity?",
"answer":"POCO Entity is Plain old CLR objects. These can be used as domain entities with our models."
},{"id":"27",
"q":"27) What are the different approaches supported in the Entity Framework to create Entity Model?",
"answer":"Below are the different approaches supported in the Entity Framework to create Entity Model –\nDatabase First\nModel First\nCode First"
},{"id":"28",
"q":"28) What is the Database First Approach? ",
"answer":"This approach is suitable, if we have a database already created and ready to use it. Using the existing database, we can create the Entity Models."
},{"id":"29",
"q":"29) What is the Model First Approach?",
"answer":"This approach is suitable, when we prefer to create the Entity Models first and derive the database from the Entity Models."
},{"id":"30",
"q":" 30) What is the Code First Approach? ",
"answer":"This approach is suitable, when we prefer to create the Domain classes first and derive the database from the Domain classes."
},{"id":"31",
"q":"31) What are the advantages of Database First Approach? ",
"answer":"Below are the advantages of Database First Approach –\nEasy to create entity models if there is an existing database.\nPreferred approach for data intensive applications."
},{"id":"32",
"q":" 32) What are the disadvantages of Database First Approach?",
"answer":"Below are the disadvantages of Database First Approach –\nOnce we create a edmx file from an existing database, huge pile of code is generated.\nIf we want to add the additional functionality to the models generated, we need to extend the models. "
},{"id":"33",
"q":"33) What are the advantages of Model First Approach?",
"answer":"Below are the advantages of Model First Approach –\nModel first approach gives the flexibility to design the Entity Models independently and gives an option to improve at later stages.\nModel classes can be created by drawing it in the edmx designer, so no much of database is required. "
},{"id":"34",
"q":"34) What are the advantages of Code First Approach?",
"answer":"Below are the advantages of Code First Approach –\nBased on business objects we can decide the database structure.\nWe can decide which classes need to be serialized and can specify the collection to eager load.\nGood for smaller applications. "
},{"id":"35",
"q":"35) What are the disadvantages of Code First Approach?",
"answer":"Below are the disadvantages of Code First Approach –\nAll database related stuffs should be included in the code.\nFor Stored Procs, we need to use the Fluent APIs to write it in code.\nNot good for data intensive applications."
},{"id":"36",
"q":"36) What are the Entity States supported in Entity Framework?",
"answer":"Below are the States supported in Entities during lifetime –\nAdded\nDeleted\nModified\nUn Changed\nDetached "
},{"id":"37",
"q":"37) What is Connected Scenario in Entity Framework?",
"answer":"Connected Scenario is when the Entity is retrieved from the database and some operations like modification is done in the same context. "
},{"id":"38",
"q":"38) What is Disconnected Scenario in Entity Framework?",
"answer":"Disconnected Scenario is when the Entity is retrieved from the database and some operations like modification is done in the different context. In this scenario context does not understand the changes done so we have to specify the changes done outside of context."
},{"id":"39",
"q":"39) How we can increase the performance of Entity Framework? ",
"answer":"Below are the points we can consider increasing the performance –\nDisable the Change Tracking if it’s not required.\nUse the compiled query whenever required.\nAvoid using Views\nFetch the required data from database."
},{"id":"40",
"q":"40) What are the ways we can load the related entities in Entity Framework?",
"answer":"Below are the ways to load the entities in Entity Framework –\nLazy Loading\nEager Loading\nExplicit Loading"
},{"id":"41",
"q":"41) What is Lazy Loading in Entity Framework?",
"answer":"Lazy Loading is the default behavior of Entity Framework, wherein the dependent/related entities are loaded once they are accessed for the first time."
},{"id":"42",
"q":" 42) Give an example for Lazy Loading? ",
"answer":"Consider a scenario of Student and Courses. Student can enroll to multiple Courses.\nFilter the Student based on Student Id.\nStudent s = dbContext.Students.FirstOrDefault(a => a. StudentId == sId);\nLoad all the Courses related to Student.\nList<Course> courses = s.Courses;"
},{"id":"43",
"q":" 43) What is Eager Loading in Entity Framework?",
"answer":"Eager Loading will load the dependent/related entities at once. Unlike Lazy loading, Eager loading will do only one database call and get all the dependent entities."
},{"id":"44",
"q":"44) Give an example for Eager Loading?",
"answer":"Consider a same Student scenario -\nStudent s = dbContext. Students.Include(s => s. Courses).FirstOrDefault(s => s. StudentId == sId);"
},{"id":"45",
"q":" 45) What is Explicit Loading in Entity Framework? ",
"answer":"Be default Entity Framework supports Lazy loading, but we can disable the Lazy loading and we can still load the dependent/related entities by calling “Load” method."
},{"id":"46",
"q":"46) Give an example for Explicit Loading?",
"answer":"Continuing Student Scenario -\nStudent s = dbContext. Students.FirstOrDefault(a => a. StudentId == sId);\ndbContext.Entry(s).Reference(s => s. Courses).Load(); "
},{"id":"47",
"q":" 47) Which type of loading is good in which scenario?",
"answer":" Use Eager Loading, when the relations are not too much so that we can get the data in one database query.\nUse Eager Loading, if you are sure that we are going to use the dependent/related entities.\nIf there are one-to-many relations use Lazy loading and if the dependent/related entities are not required down the line.\nWhen Lazy Loading is turned off, use Explicit loading when you are not sure whether dependent/related entities are not required down the line."
},{"id":"48",
"q":" 48) Can we use Stored Procedures in Entity Framework? ",
"answer":"Yes. "
},{"id":"49",
"q":"49) Do Entity Framework handle the Change Tracking?",
"answer":"Yes. "
},{"id":"50",
"q":"50) How Entity Framework handles the Change Tracking? ",
"answer":"Entity Framework supports automatic change tracking of all the loaded entities through context class."
},{"id":"51",
"q":" 51) What is the minimum requirement for Change Tracking in Entity Framework? ",
"answer":"If Entity Framework need to handle Change Tracking, each entity should have Entity Key (Primary Key). "
}
]
}
"iq":[{"id":"1",
"q":"1) What is Entity Framework?",
"answer":"Entity Framework is an ORM from Microsoft that will enable the developers to work with domain specific objects, which eliminates the extra code being written in the data access layer. "
},
{"id":"2",
"q":"2) Why to use Entity Framework? ",
"answer":"Writing ADO.NET code and managing it is a tedious job. To avoid this, Microsoft has provided a solution - Entity Framework. Entity Framework reduces a great deal of code by enabling to work with relational data as domain specific objects. "
},
{"id":"3",
"q":"3) What is the difference between Entity Framework and ADO.NET?",
"answer":" ADO.NET:-\n1) ADO.NET is faster.\n2) We need to write so much code to talk to database.\n3) Performance is better than Entity Framework.\n\nEntity Framework:-\n1) Entity Framework will be around the ADO.NET, which means ADO.NET is faster than Entity Framework.\n2)Easy to use. As an Entity Framework will talk to database without much code involved.\n3)Performance is not good compared to ADO.NET."
},
{"id":"4",
"q":" 4) What is the difference between Entity Framework and LINQ to SQL?",
"answer":"LINQ to SQL\n1) Supports only for SQL database.\n2) Allows only one-to-one mapping between the entity classes and the relational tables.\n3)dbml file is generated for maintaining the relationships.\n4)No Support for Complex Types\n5)Supports Rapid application development with SQL Server.\n\nEntity Framework\n1) Supports databases like SQL, MySQL, DB2 etc.\n2) Allows one-to-one, one-to-many & many-to-many mappings between the Entity classes and the relational tables.\n3) Relationships are maintained in 3 different files - .csdl, .msl and .ssdl\n4)Supports Complex Types\n5) Supports Rapid application development with SQL Server, DB2, MySQL etc."
},
{"id":"5",
"q":"5) What are the components of Entity Framework Architecture? ",
"answer":"\nBelow are the components of Entity Framework –\nEntity Data Model (EDM)\nLINQ to Entities\nEntity SQL\nObject Service\nEntity Client Data Provider\nADO.Net Data Provider"
},
{"id":"6",
"q":"6) What are the parts of Entity Data Model (EDM)?",
"answer":"\nBelow are the parts of Entity Data Model –\nConceptual Model\nMapping\nStorage Model"
},
{"id":"7",
"q":"7) How to create Entity Data Model (EDM)?",
"answer":" Add New Item -> ADO.NET Entity Data Model, which generates file with .edmx extension. "
},
{"id":"8",
"q":"8) What does .edmx consists of?",
"answer":".edmx file is a XML file and it has Conceptual Model, Storage Model and Mapping details i.e,\nSSDL (Store schema definition language)\nCSDL (Conceptual schema definition language)\nMSL (Mapping specification language)"
},
{"id":"9",
"q":"9) What is Conceptual Model? ",
"answer":"Conceptual Models are the model classes which contain the relationships. These are independent of the database design."
},
{"id":"10",
"q":"10) What is Storage Model?",
"answer":"Storage Models are our database design models, which contains database tables, views, stored procs and keys with relationships."
},
{"id":"11",
"q":"11) What is Mapping?",
"answer":"The Mapping will have the information on how the Conceptual Models are mapped to Storage Models."
},
{"id":"12",
"q":" 12) What is LINQ to Entities?",
"answer":"LINQ to Entities is a query language which we used to write queries against the object models and the query result will return the entities defined in the Conceptual Model."
},
{"id":"13",
"q":"13) What is Entity SQL?",
"answer":"Entity SQL is a query language is like LINQ to Entities. This is a bit complex compared to LINQ to Entities. A developer who is using this should learn this separately."
},
{"id":"14",
"q":"14) What is the role of Entity Client Data Provider?",
"answer":"Responsibility of Entity Client Data Provider is to convert the LINQ to Entities or Entity SQL queries to a SQL query, which is understood by the underlying database. This finally communicates with ADO.NET Data Provider which in turn used to talk to the database."
},
{"id":"15",
"q":" 15) What is the meaning of Pluralize and Singularize in Entity Framework?",
"answer":" Pluralize and Singularize gives the meaningful naming conventions for objects.\nWe will get this option while adding an edmx file. On selecting this option Entity Framework will adhere to Singular or Plural coding conventions. "
},
{"id":"16",
"q":"16) What is DB Context ? ",
"answer":"When we create a edmx file, it will have the list of entities and context class which will be derived from DB Context class. "
},
{"id":"17",
"q":"17) What is the role of DB Context?",
"answer":"DBContext will be responsible for Insert, Update and Delete functionalities of the entities. It acts like a bridge between the database and entity classes. "
},
{"id":"18",
"q":" 18) What is Object Context? ",
"answer":"Object Context manages all the database operations, like database connection, and manages various entities of the Entity Model. DB Context is a wrapper around Object Context."},
{"id":"19",
"q":"19) What is the difference between ObjectContext and DbContext?",
"answer":"Conceptually, both these are here for the same reason.\nDBContext is wrapper around Object Context.\nPrior to EF 4.1, EDM used to use Object Context as base class for Context classes.\nThere were some difficulties been observed in Object Context so now Db Context is introduced in EF 6.0 and this is used for all the development models –\nDatabase First, Model First and Code First.\nObject Context supports complied queries, but DB Context not.\nObject Context supports self-tracking entities, but DB Context does not.\nDB Context is thread safe, but Object Context not. "
},
{"id":"20",
"q":"20) What is Entity Set?",
"answer":"Entity Set holds the Entity Types and this most of the times compared with a database table. "
},
{"id":"21",
"q":"21) What is Association Set?",
"answer":"Association Set is used to define the relationship between Entity Sets. "
},
{"id":"22",
"q":"22) What is Entity Container? ",
"answer":" It is a wrapper for Association Sets and Entity Sets and this is a critical to query a model. "
},
{"id":"23",
"q":"23) What is Entity Graph?",
"answer":" Entity Graph is when one entity has a relation with other entity."
},{"id":"24",
"q":" 24) What is T4 Templates? ",
"answer":"T4 Template (Text Template Transformation Toolkit) will generate the C# code based on edmx XML file. (.tt extension)"
},{"id":"25",
"q":"25) What are the types of Entities in Entity Framework? ",
"answer":"\nPOCO Entity\nDynamic Proxy"
},{"id":"26",
"q":"26) What is POCO Entity?",
"answer":"POCO Entity is Plain old CLR objects. These can be used as domain entities with our models."
},{"id":"27",
"q":"27) What are the different approaches supported in the Entity Framework to create Entity Model?",
"answer":"Below are the different approaches supported in the Entity Framework to create Entity Model –\nDatabase First\nModel First\nCode First"
},{"id":"28",
"q":"28) What is the Database First Approach? ",
"answer":"This approach is suitable, if we have a database already created and ready to use it. Using the existing database, we can create the Entity Models."
},{"id":"29",
"q":"29) What is the Model First Approach?",
"answer":"This approach is suitable, when we prefer to create the Entity Models first and derive the database from the Entity Models."
},{"id":"30",
"q":" 30) What is the Code First Approach? ",
"answer":"This approach is suitable, when we prefer to create the Domain classes first and derive the database from the Domain classes."
},{"id":"31",
"q":"31) What are the advantages of Database First Approach? ",
"answer":"Below are the advantages of Database First Approach –\nEasy to create entity models if there is an existing database.\nPreferred approach for data intensive applications."
},{"id":"32",
"q":" 32) What are the disadvantages of Database First Approach?",
"answer":"Below are the disadvantages of Database First Approach –\nOnce we create a edmx file from an existing database, huge pile of code is generated.\nIf we want to add the additional functionality to the models generated, we need to extend the models. "
},{"id":"33",
"q":"33) What are the advantages of Model First Approach?",
"answer":"Below are the advantages of Model First Approach –\nModel first approach gives the flexibility to design the Entity Models independently and gives an option to improve at later stages.\nModel classes can be created by drawing it in the edmx designer, so no much of database is required. "
},{"id":"34",
"q":"34) What are the advantages of Code First Approach?",
"answer":"Below are the advantages of Code First Approach –\nBased on business objects we can decide the database structure.\nWe can decide which classes need to be serialized and can specify the collection to eager load.\nGood for smaller applications. "
},{"id":"35",
"q":"35) What are the disadvantages of Code First Approach?",
"answer":"Below are the disadvantages of Code First Approach –\nAll database related stuffs should be included in the code.\nFor Stored Procs, we need to use the Fluent APIs to write it in code.\nNot good for data intensive applications."
},{"id":"36",
"q":"36) What are the Entity States supported in Entity Framework?",
"answer":"Below are the States supported in Entities during lifetime –\nAdded\nDeleted\nModified\nUn Changed\nDetached "
},{"id":"37",
"q":"37) What is Connected Scenario in Entity Framework?",
"answer":"Connected Scenario is when the Entity is retrieved from the database and some operations like modification is done in the same context. "
},{"id":"38",
"q":"38) What is Disconnected Scenario in Entity Framework?",
"answer":"Disconnected Scenario is when the Entity is retrieved from the database and some operations like modification is done in the different context. In this scenario context does not understand the changes done so we have to specify the changes done outside of context."
},{"id":"39",
"q":"39) How we can increase the performance of Entity Framework? ",
"answer":"Below are the points we can consider increasing the performance –\nDisable the Change Tracking if it’s not required.\nUse the compiled query whenever required.\nAvoid using Views\nFetch the required data from database."
},{"id":"40",
"q":"40) What are the ways we can load the related entities in Entity Framework?",
"answer":"Below are the ways to load the entities in Entity Framework –\nLazy Loading\nEager Loading\nExplicit Loading"
},{"id":"41",
"q":"41) What is Lazy Loading in Entity Framework?",
"answer":"Lazy Loading is the default behavior of Entity Framework, wherein the dependent/related entities are loaded once they are accessed for the first time."
},{"id":"42",
"q":" 42) Give an example for Lazy Loading? ",
"answer":"Consider a scenario of Student and Courses. Student can enroll to multiple Courses.\nFilter the Student based on Student Id.\nStudent s = dbContext.Students.FirstOrDefault(a => a. StudentId == sId);\nLoad all the Courses related to Student.\nList<Course> courses = s.Courses;"
},{"id":"43",
"q":" 43) What is Eager Loading in Entity Framework?",
"answer":"Eager Loading will load the dependent/related entities at once. Unlike Lazy loading, Eager loading will do only one database call and get all the dependent entities."
},{"id":"44",
"q":"44) Give an example for Eager Loading?",
"answer":"Consider a same Student scenario -\nStudent s = dbContext. Students.Include(s => s. Courses).FirstOrDefault(s => s. StudentId == sId);"
},{"id":"45",
"q":" 45) What is Explicit Loading in Entity Framework? ",
"answer":"Be default Entity Framework supports Lazy loading, but we can disable the Lazy loading and we can still load the dependent/related entities by calling “Load” method."
},{"id":"46",
"q":"46) Give an example for Explicit Loading?",
"answer":"Continuing Student Scenario -\nStudent s = dbContext. Students.FirstOrDefault(a => a. StudentId == sId);\ndbContext.Entry(s).Reference(s => s. Courses).Load(); "
},{"id":"47",
"q":" 47) Which type of loading is good in which scenario?",
"answer":" Use Eager Loading, when the relations are not too much so that we can get the data in one database query.\nUse Eager Loading, if you are sure that we are going to use the dependent/related entities.\nIf there are one-to-many relations use Lazy loading and if the dependent/related entities are not required down the line.\nWhen Lazy Loading is turned off, use Explicit loading when you are not sure whether dependent/related entities are not required down the line."
},{"id":"48",
"q":" 48) Can we use Stored Procedures in Entity Framework? ",
"answer":"Yes. "
},{"id":"49",
"q":"49) Do Entity Framework handle the Change Tracking?",
"answer":"Yes. "
},{"id":"50",
"q":"50) How Entity Framework handles the Change Tracking? ",
"answer":"Entity Framework supports automatic change tracking of all the loaded entities through context class."
},{"id":"51",
"q":" 51) What is the minimum requirement for Change Tracking in Entity Framework? ",
"answer":"If Entity Framework need to handle Change Tracking, each entity should have Entity Key (Primary Key). "
}
]
}