DbSetrepresents the set of entities. In a database, a group of similar entities is called an Entity Set.
DbSetenables the user to perform various operations like add, remove, update, etc. on the entity set.
DbSetproperties to participate in CRUD operations.
DbSetproperty of all the entities, and it keeps the collection of entities in memory.
DbSetis responsible for performing all the basic CRUD (Create, Read, Update and Delete) operations on each of the Entity.
DbSetoperations are used to change any property of the entity in the EF Core. The most essential methods of the
DbSetand the queries are specified using LINQ.
FirstOrDefaultcriteria, there is only one entity returned from a large group of entities.
SingleOrDefaultone record entity is returned but that entity should be relevant to the required field otherwise it will be discarded.
Findmethod is familiar to the users of the older version of Entity Framework that use to support the
Findmethod requires a Key-value parameter in the entity to determine the required entity otherwise it gives null as the result.
count. The query is not executed until the
foreachloop is utilized.
GroupBymethod which is used to group all the entity results according to their categories.
DbSetcan be used.
Includeproperty is used to include the related entity type into the database.
DbContextthat the entity is read-only and does not need to be tracked by the context, this will eventually decrease the load on the system, hence improving the performance.
Addmethod is used and then after tracking the entity by
DbContextthe state of the entity is changed to Added.
AddRangemethod is used, it is like the
Addmethod but in
AddRangemethod, all the records are saved in just a single step instead of adding them all individually.
DbSetthere are 3 key methods:
DbSet, first it checks whether the data which is to be modified is being tracked or not.
DbContext, then the modifications must be updated using another method.
DbSet<T>.Updatemethod is used, so whenever the application is loaded, it changes the state of the entity as Updated.
Updatemethod is using
DbSet<T>class and provides different methods to work with an individual or multiple entities.
DbSet. For deleting any data, it will first check whether the data which is to be deleted is being tracked by the context or not.
DbSet<T>.Removemethod which sets the state of the entity as
Deleted, after this when the changes are saved, the
DELETEstatement is generated and executed by the Database.