The Entity Framework (EF) model constructor always refers to your class names when creating tables in the database in the first code approach. In your case, this is Person and Company . EF never refers to properties in your context when creating database tables.
When creating the table, he tries to pluralize the names, so Person got the plural before People and Company got the plural before Companies .
As a quick test, if you change the name of your Company class to Corporation , then the table name will be created as Corporations . I also changed the corresponding Corporation property name in the class context to FooBar
Here is what I did to check this out:
public class Person { public int PersonId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Corporation { public int CorporationId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Context : DbContext { public Context() : base("name=codefirst") { } public DbSet<Person> People { get; set; } public DbSet<Corporation> FooBar { get; set; } }
EF now goes ahead and instead creates the Corporations table ( Corporations plural) and completely ignores the name of the FooBar property that is present in the context class.
It was just a coincidence in your code that you called a property in your context a class like People , which has the plural Person . It embarrassed you and made you think.
source share