Reputation:
What are pros and cons for mapping table DbSet in the DbContext in EF Core? Why should we do it like this or why not?
public DbSet<CategoryBooks> CategoryBooks { get; set; }
Thanks in advance! :)
Upvotes: 0
Views: 1380
Reputation: 712
The main idea behind Entity Framework is that it represents the data in the database in the form of entities which are c# variables. So for example the table would be represented as a collection of variables with each variable represents the table row and the data members of the variable represents the named columns of the table.
So instead of writing queries to insert,delete,update rows, what we do is apply these operations on the c# collection and then entity framework takes care of what to do in backend.
In the code above the collection is CategoryBooks that represent the table. Each item in this collection is lets say a book with some property. so you can do easy modifications to the books collection for example you want to modify the property of a certain book or you want to delete the book from the collection or add some new books to the collection. All you do programmatically in c#. You don't have to write queries specifically to achieve CRUD functionality. So that's an advantage.
Upvotes: 0