I'm trying to find a list of examples of Entity Framework's default naming conventions. I gather that Tables are <Entity>+s
e.g. Users... Foreign Keys are User_Id But I would like to see a list of all out-of-the box conventions - IE what entity framework is going to call my objects.
I'm not looking for the types of the conventions - I got that. I am looking for definitions/examples of what Entity Framework's default conventions will name my database objects. To be clear, I have not added or removed any conventions. EF comes with a number of default conventions for generating databse objects - I want to know what EF's out-of-the box default conventions are going to name my database objects.
The reason I require this is because although I am using CodeFirst, I will be creating my database objects by hand rather than making EntityFramework generate it for me (my colleague is insisting on this). Therefore I need to know what I should name my Tables, Columns, Foreign Keys...... So that Entity Framework will find/map them with no explicit mappings required.
Eg
EF Default TableName Convention
<Entity> + 's' (e.g ***Users***)
EF Default Foreign Key Convention
<Entity> + 'Id' (e.g ***UserId***)
EF Default Primary Key Convention
***Id***
Where can I find this?
Configuring a primary key By convention, a property named Id or <type name>Id will be configured as the primary key of an entity. Owned entity types use different rules to define keys. You can configure a single property to be the primary key of an entity as follows: Data Annotations.
Conventions are a set of rules hard-baked into Entity Framework Core that govern how the model will be mapped to a database schema. Most of the time, especially with new application development, it makes sense to follow EF Core's conventions when developing the model.
By default, EF creates all the DB objects into the dbo schema. EF will create a DB table with the entity class name suffixed by 's' e.g. Student domain class (entity) would map to the Students table. EF will create a primary key column for the property named Id or <Entity Class Name> + "Id" (case insensitive).
Primary Key Convention Code First infers that a property is a primary key if a property on a class is named “ID” (not case sensitive), or the class name followed by "ID". If the type of the primary key property is numeric or GUID it will be configured as an identity column.
EF does not provide a mechanism to retrieve the set of conventions used. You can only remove pre configured conventions.
You can find the documented convention list on MSDN
Initially EF allowed you to customize the conventions but now that part is removed from API.
Edit
Convention: Table Name
Default: Entity + s (e.g Users)
PluralizingTableNameConvention
Convention: Foreign Key Relation
Default: Entity + Id (e.g UserId)
NavigationPropertyNameForeignKeyDiscoveryConvention
Convention: Primary Key
Default: Id
IdKeyDiscoveryConvention
Maybe the System.Data.Entity.ModelConfiguration.Conventions namespace is what you're looking for.
This namespace contains all naming conventions.
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