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.
Alternate keys and multicolumn keys
From the course: Using Entity Framework Core with Legacy Databases
Alternate keys and multicolumn keys
- [Instructor] Some relationships, especially in Legacy databases, don't use the primary key of a table to relate to another table. We're going to add a relationship in this video to a table on an alternate key. In our model, we have a Salesperson and a SalesGroup. A Salesperson has a SalesGroupState and a SalesGroupType but no reference to the full SalesGroup. It would also be nice if we could add a collection of Salespeople to a SalesGroup to easily get the Salespeople that belong to that group. Starting here in the Salesperson model, the first thing I notice is that we have a SalespersonNavigation, and an InverseSalespersonNavigation. I don't expect these on the model, so let's go look at the context and see where they came from. We'll scroll down to Salesperson, and then scroll down to this navigation collection. Those navigation properties are part of a foreign key that references one Salesperson to another. Since we don't need to associate Salespeople with other Salespeople…
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.