C# – Create a complex data model – ASP.NET MVC with EF Core – Video

Creating a complex data model with the previous data model in ASP.NET is actually a challenging task.

The model in general looks like this:

It is not “extremely” complex, but it is something bigger than the previous 3 tables that we had before. Thus, in this tutorial some additional classes were added – a class per table. The seeding method was changed (twice actually), in order to seed data to the classes and a lot of data annotations were used, in order to display the data from the tables the way it was intended. E.g. in the Enrollments.cs entity, the annotation [DisplayFormat(NullDisplayText="No grade")] was used to display “no grade” when there was no entry for a grade in the DB. This is how the Student.cs class looks like with the annotations:

At the end of the video, the SQL written to display all courses and all teachers is this one:

The rest of the classes are available in GitHub here – https://github.com/Vitosh/ASP/tree/master/EFCoreAsp.NetMvcWebApp/ContosoUniversity005

Enjoy!

Tagged with: , , , ,