Entity framework is an open source ORM(Object Relational Mapping)Framework for .Net applications which is supported by Microsoft. It activates the developers to work with the data using the objects of domain –specific classes without focusing on the database tables and columns where the data will be stored. By this entity framework, developers may be able to work at the higher level of abstraction when the developers deal with the data. With the help of entity framework, we can create and maintain data-oriented applications with less code when compared with the traditional applications.
Entity framework is object-relational mapper which highlights the .Net developers to work with databases using the .Net objects. It eliminates the need for accessing the code of the data that the developers need to write.
The following image shows the application
Entity framework fits in between the business entities and also the databases. It saves the data in the business properties entities and also retrieves the data from the database and also converts it into the object automatically.
What is the need for Entity Framework?
Entity Framework is ORM. The main focus of the ORM is to increase the developer’s productivity by reducing the redundant task of the application.
- Entity framework can create the required database commands for reading or writing the data in the database and also execute them for us.
- By querying, we can express our queries against our domain of the object using LINQ to entities.
- This executes the relevant query in the database and materializes the results into instances of the domain object to work with the app.
Other ORMs in the marketplace exist, such as NHibernate and LLBL Gen Pro.
Entity Framework has a granular mapping layer so that we can customize the mappings.
Entity Framework features
- Cross-platform- This core is a cross-platform framework that runs on Windows and Linux.
- Modeling- Entity Framework supports us in using the LINQ queries to retrieve the data from the database. This database provider will convert these LINQ queries to the database-specific query language.
- Change tracking- Entity framework will keep track of changes that occur to instances of the entities which need to submit to the database.
- Saving- Entity framework will execute the INSERT, UPDATE, and DELETE commands to the database based on the changes that occurred to the entities when this occurs to the entities when we call the savechanges() method. Entity framework also provides the asynchronous “savechangesAsync()” method.
- Concurrency-This entity framework will use an optimistic concurrency by default to protect the overwriting changes made by other users when the database fetches the data.
- Transactions- This framework will automate transaction management when querying or saving data.
How does the entity framework work?
Entity Framework model API will be able to map domain classes to the database schema, translate and execute LINQ queries to SQL, track changes that occurred on entities during their lifetime, and save changes to the database..
Entity Data Model,
The first task of EF API is to build an Entity Data Model. EDM is a memory representation of the entire metadata: conceptual model, storage model, and mapping.
- Conceptual model: This EF creates conceptual models from the domain classes, context class, and default conventions followed in your domain classes and configuration.
- Storage Model: EF builds the storage model for the underlying database schema. Here code-first approach will be inferred from the conceptual model. The database approach will be inferred from the targeted database.
- Mappings: This EF includes mapping information on how the conceptual model maps to the database schema.
Context class Entity Framework- This concept is important while working With EF 6 and EF core, representing a session with an underlying database that performs CRUD(Create, Read, Update, Delete)operations.
Questions
- What is Entity Framework?
- How does EF work?