Entity Framework

Add Record / Add Multiple Records In Entity Framework

In this tutorial let us look at how to add a record, add multiple records to the database. Before inserting records into the database, we must add the entities to the context first. To do that we use the Add & AddRange methods. Once the records are added to the context, we can call the SaveChanges method, which sends the insert query to the database. The EF also takes care of updating identity values generated in the database in the entity. We also show you how to add related entities or data.

Add Record / Add Multiple Records In Entity Framework Read More »

Entity States in Entity Framework

The Entity States represents the state of an entity. The Entity state can be Added, Deleted, Modified, Unchanged or Detached. DbContext tracks & manages the entity state of every entity using the ChangeTracker. For example, when we add a new entity to Context using the Add method, the DbContext sets the state of the entity as Added. When you call the SaveChanges method, the context sends an Insert Query to the database. Similarly, it uses it to create Insert,Update or Delete SQL queries, when we invoke the SaveChanges

Entity States in Entity Framework Read More »

Entity Framework Save Changes

Entity Framework SaveChanges method of DbContext class handles the persisting of data to the database. When we use the SaveChanges it prepares the corresponding insert, update, delete queries. It then wraps them in a Transaction and sends it to the database. If anyone of the query fails all the statements are rolled back. The Context also manages the entity objects during run time, which includes populating objects with data from a database, change tracking, etc.

Entity Framework Save Changes Read More »

Explicit Loading in Entity Framework

Explicit Loading is a technique we query and load the related entities with an explicit call. Explicit loading works very similar to Lazy Loading, but the loading of the related entities happens only after an explicit call. The loading only when we invoke the Load method of the related entity’s DBEntityEntry object. In eager loading, we query the related entities along with the main entity in a single Query. In Lazy loading, EF loads the load related entities whenever we access the related Property.

Explicit Loading in Entity Framework Read More »

Scroll to Top