So I have a table people which is like this
Id Name
1 John
2 Mike
3 Sophie
And I have a table Calls
Id IdReceptor IdRequired
1 1 2
2 1 1
3 2 3
4 3 1
Basically a person answers a telephone call, that person is the receptor, the one on the phones requires to talk with another person, it can be the same person who answered, or other, so we have this table design, IdReceptor and IdRequired both are foreign keys to people
How can I model this using EF4 Code First?
For example like so:
You can introduce collections in
Personif you want and add additional mapping with annotations or Fluent API or you can make thePersonnavigation propertiesvirtualif you want lazy loading. But the code above is a simple solution. EF will detect two one-to-many relationships by convention.