c# Entity framework core assignment: Add models and tables
Before the assignment here is what we learned so far
we already have created :
!) building the modeel which is the Article model
2) we have added migration
3) we apply the migration
4) we saw that the database was created and the table Articles was created as well
5) we have understood the __EFMigrationsHistory
6) we have learned how to update existing table and remove migration
7) Renaming Column and change nullable
8) when to add a migration and delete table
9) rolling back to old migrations
10)Navigating Migrations and Delete Table in Entity Framework Core
11) get-migration and drop-database
12)Migration Seeding Data in Entity Framework Core with C#
13) Refining Database Schema using Data Annotations in Entity Framework Core
14) Leveraging C# Entity Framework Core Data Annotations: Key and Required Attributes
15) Entity Framework Core in C#: A Deep Dive into Data Annotations - MaxLength and NotMapped
16)c# entitiy framework core Power tools
Recommended by LinkedIn
Expanding Your Entity Framework Skills in C#: Adding Models and Tables
Welcome back to our series on mastering Entity Framework Core with C#. In our previous articles, we've built a solid foundation, covering everything from model creation to migration management. Now, it's time to put our learned skills into practice with a hands-on assignment.
Now, let's expand our application's database schema by adding three new classes: Author, Publisher, and SubCategory. Here's a detailed breakdown of each class:
1. Author Class
Table Name: Authors
Properties:
AuthorId (int, primary key)
FirstName (string, required, max length 50)
LastName (string required)
BirthDate (DateTime)
Location (string)
FullName (computed property, not stored in database)
2. Publisher Class
Table Name: Publishers
Properties:
PublisherId (int, primary key)
Name (string, required)
Location (string)
SubCategory Class
Table Name: SubCategories
Properties:
SubCategoryId (int, primary key)
Name (string, required, max length 50)
Integrating Classes into ApplicationDBContext
Next, integrate these classes into your ApplicationDBContext by defining them as DbSet properties.
Migrating Changes
With the classes defined, use the Package Manager Console to add and apply the new migration:
add-migration AddingAuthorsPublishersSubCategories
update-database
Conclusion
This assignment will consolidate your understanding of Entity Framework Core in C#. Remember, continuous practice is key to mastering any technology.
Stay curious and keep coding!