From the course: Using Entity Framework Core with Legacy Databases
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Understanding the generated context
From the course: Using Entity Framework Core with Legacy Databases
Understanding the generated context
- [Instructor] Now that we have a model and a database context, we can look at their details so we can begin to make improvements. We'll start by looking in the models folder at Customer.cs. The first thing to notice is that the scaffolding process generated partial classes. The partial class allows us to separate our changes from the generated code. The next thing we see is properties for each field in the table. The final thing, in some model classes, is this collection. This collection represents the orders that are related to this customer. In the constructor, we see that this set has been instantiated to an empty of orders. This way the property is not null even if it has not been populated from the database. Now let's move on to the context, HPlusSportsContext. Note that the context is also partial class and can be extended in another file that won't be overwritten when the generation happens again. The two main methods we'll be looking at in the context are OnConfiguring and…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.