Entity Framework Core pros and cons of DBSet

ef-core-2.0 entity-framework-core

Question

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! :)

1
0
12/5/2017 6:12:45 PM

Accepted Answer

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.

0
12/5/2017 6:23:45 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow