Tutorial by Examples

So let's say again that you have the following model: public class Person { public int PersonId { get; set; } public string Name { get; set; } } public class Car { public int CarId { get; set; } public string LicensePlate { get; set; } } public class MyDemoContext : DbContext ...
Mapping one-to-one (when both sides are required) is also a tricky thing. Let's imagine how this could be represented with foreign keys. Again, a CarId in People that refers to CarId in Car, and a PersonId in Car that refers to the PersonId in People. Now what happens if you want to insert a car r...
And to finish off, let's briefly look at the case when both sides are optional. By now you should be really bored with these examples :), so I'm not going into the details and play with the idea of having two FK-s and the potential problems and warn you about the dangers of not enforcing these rule...

Page 1 of 1