I'm using EF 6, have two simple POCO class as below:
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Company
{
public int CompanyId { get; set; }
public string Name { get; set; }
}
and my context
public class Context : DbContext
{
public Context() : base("name=codefirst")
{
}
public DbSet<Person> People { get; set; }
public DbSet<Company> Corporation { get; set; }
}
And EF generated tables : dbo.Companies and dbo.People
My question is why one table name is People and other table name is Companies (I know why is pluralized). I mean, One table use the property name, and the other table use the class name ?
Thanks in advance!
Both are mapped by using their class name.
The one that probably confused you is the mapping of the Person class. It is one of the EF pluralization rules, since people is the plural form of person(meaning more than one person), EF mapped it as People.
On the other hand, it simply mapped the Company class as Companies.
You can turn off EF pluralization convention by adding this code in the OnModelCreating()
method if you don't like it:
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With