17) What is the role of DB Context?
DBContext will be responsible for Insert, Update and Delete functionalities of the entities. It acts like a bridge between the database and entity classes.
- DBContext is wrapper around Object Context.
- Prior to EF 4.1, EDM used to use Object Context as base class for Context classes.
- There 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 –
- Database First, Model First and Code First.
- Object Context supports complied queries, but DB Context not.
- Object Context supports self-tracking entities, but DB Context does not.
- DB Context is thread safe, but Object Context not.
20) What is Entity Set?
Entity Set holds the Entity Types and this most of the times compared with a database table.
21) What is Association Set?
Association Set is used to define the relationship between Entity Sets.
22) What is Entity Container?
It is a wrapper for Association Sets and Entity Sets and this is a critical to query a model.
23) What is Entity Graph?
Entity Graph is when one entity has a relation with other entity.
24) What is T4 Templates?
T4 Template (Text Template Transformation Toolkit) will generate the C# code based on edmx XML file. (.tt extension)
25) What are the types of Entities in Entity Framework?
- POCO Entity
- Dynamic Proxy
26) What is POCO Entity?
POCO Entity is Plain old CLR objects. These can be used as domain entities with our models.
27) What are the different approaches supported in the Entity Framework to create Entity Model?
Below are the different approaches supported in the Entity Framework to create Entity Model –
- Database First
- Model First
- Code First
28) What is the Database First Approach?
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.
29) What is the Model First Approach?
This approach is suitable, when we prefer to create the Entity Models first and derive the database from the Entity Models.
30) What is the Code First Approach?
This approach is suitable, when we prefer to create the Domain classes first and derive the database from the Domain classes.
31) What are the advantages of Database First Approach?
Below are the advantages of Database First Approach –
- Easy to create entity models if there is an existing database.
- Preferred approach for data intensive applications.
32) What are the disadvantages of Database First Approach?
Below are the disadvantages of Database First Approach –
- Once we create a edmx file from an existing database, huge pile of code is generated.
- If we want to add the additional functionality to the models generated, we need to extend the models.
33) What are the advantages of Model First Approach?
Below are the advantages of Model First Approach –
- Model first approach gives the flexibility to design the Entity Models independently and gives an option to improve at later stages.
- Model classes can be created by drawing it in the edmx designer, so no much of database is required.
34) What are the advantages of Code First Approach?
Below are the advantages of Code First Approach –
- Based on business objects we can decide the database structure.
- We can decide which classes need to be serialized and can specify the collection to eager load.
- Good for smaller applications.
35) What are the disadvantages of Code First Approach?
Below are the disadvantages of Code First Approach –
- All database related stuffs should be included in the code.
- For Stored Procs, we need to use the Fluent APIs to write it in code.
- Not good for data intensive applications.
36) What are the Entity States supported in Entity Framework?
Below are the States supported in Entities during lifetime –
- Un Changed