Search code examples
entity-frameworkef-code-firstentity-relationshipone-to-manyforeign-key-relationship

FK in one to many relationship code first


In model first, when we create a one to many relationship between two entities, there will be a FK auto-created in many end, when we do in code first, do we need to add a FK property in the many end entity? Why? Thx in advance!


Solution

  • You don't need to add it. If you don't add it EF will generate it in database in the same way as it did it in model first. The question Why? refers to difference between foreign key and independent associations.