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.
Navigation properties
From the course: Using Entity Framework Core with Legacy Databases
Navigation properties
- [Instructor] Navigation properties are one of the big reasons for using Entity Framework. Rather than relying on manually joining related tables, you can use sets on the model to represent the related data. Entity Framework will automatically join the data when related data is requested. For existing databases, we may want to add or remove navigation properties that were scaffolded. When the model was created, the foreign keys were automatically converted to Entity Framework navigation properties. We can modify what was generated to remove unnecessary navigation properties. Let's start by looking at the product model in the Models folder. In the product model, we can see that we have a collection of order items. Since the product doesn't have to reference its order items, but rather the order items usually reference the product, we'll remove that side of the relationship. After removing it from the model, we'll remove it from the context. Open up the context and scroll down to the…
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.