SlideShare a Scribd company logo
table lists default code first conventions
Default
Convention For
Description
Schema By default, EF creates all the DB objects into the dbo schema.
Table Name <Entity Class Name> + 's'
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.
Primary key
Name
1) Id
2) <Entity Class Name> + "Id" (case insensitive)
EF will create a primary key column for the property named Id or <Entity Class Name> + "Id" (case
insensitive).
Foreign key
property Name
By default, EF will look for the foreign key property with the same name as the principal entity primary key
name.
If the foreign key property does not exist, then EF will create an FK column in the Db table with <Dependent
Navigation Property Name> + "_" + <Principal Entity Primary Key Property Name>
e.g. EF will create Grade_GradeId foreign key column in the Students table if the Student entity does not
contain foreignkey property for Grade.
Null column EF creates a null column for all reference type properties and nullable primitive properties e.g. string,
Nullable<int>, Student, Grade (all class type properties)
Not Null Column EF creates NotNull columns for Primary Key properties and non-nullable value type properties e.g. int, float,
decimal, datetime etc.
DB Columns
order
EF will create DB columns in the same order like the properties in an entity class. However, primary key
columns would be moved first.
Properties
mapping to DB
By default, all properties will map to the database. Use the [NotMapped] attribute to exclude property or
class from DB mapping.
Cascade delete Enabled by default for all types of relationships.
The following table list C# data type mapped with SQL Server data type.
C# Data Type Mapping to SQL Server Data Type
int int
string nvarchar(Max)
decimal decimal(18,2)
float real
byte[] varbinary(Max)
datetime datetime
bool bit
byte tinyint
short smallint
long bigint
double float
char No mapping
sbyte No mapping
(throws exception)
object No mapping

More Related Content

PPTX
DBMS: Types of keys
PPTX
Database keys
PPTX
Slide 5 keys
PPTX
Types of keys in dbms
PPTX
Keys in Database Management System
PPTX
Types of keys dbms
PDF
Selenium Locators groups 1_0_2
PDF
Locators groups 1_0_2
DBMS: Types of keys
Database keys
Slide 5 keys
Types of keys in dbms
Keys in Database Management System
Types of keys dbms
Selenium Locators groups 1_0_2
Locators groups 1_0_2

Similar to Default convention for entity framework code first (20)

PDF
How to create Xpath, CSS, DOM for your Selenium script
KEY
ExAlg Overview
PPT
Ef code first
PDF
Viastudy ef core_cheat_sheet
PDF
PofEAA and SQLAlchemy
PPTX
Scala for curious
PDF
Jazoon 2010 - Building DSLs with Eclipse
PPT
ITU - MDD - XText
PPTX
Net database
PPTX
Quick And Dirty Databases
PDF
Presentation pdi data_vault_framework_meetup2012
PDF
PDI data vault framework #pcmams 2012
PPTX
Xml session
PPT
Sedna XML Database System: Internal Representation
PDF
Creating Domain Specific Languages in Python
PDF
Whats the Schema Table Column Row Attribute Entity Pri.pdf
PDF
DP080_Lecture_2 SQL related document.pdf
PPT
displaytag
PDF
Data Analysis with R (combined slides)
PDF
Web app development_database_design_10
How to create Xpath, CSS, DOM for your Selenium script
ExAlg Overview
Ef code first
Viastudy ef core_cheat_sheet
PofEAA and SQLAlchemy
Scala for curious
Jazoon 2010 - Building DSLs with Eclipse
ITU - MDD - XText
Net database
Quick And Dirty Databases
Presentation pdi data_vault_framework_meetup2012
PDI data vault framework #pcmams 2012
Xml session
Sedna XML Database System: Internal Representation
Creating Domain Specific Languages in Python
Whats the Schema Table Column Row Attribute Entity Pri.pdf
DP080_Lecture_2 SQL related document.pdf
displaytag
Data Analysis with R (combined slides)
Web app development_database_design_10
Ad

Recently uploaded (20)

PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Digital Strategies for Manufacturing Companies
PDF
System and Network Administration Chapter 2
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Transform Your Business with a Software ERP System
PDF
medical staffing services at VALiNTRY
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
Digital Systems & Binary Numbers (comprehensive )
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Reimagine Home Health with the Power of Agentic AI​
Digital Strategies for Manufacturing Companies
System and Network Administration Chapter 2
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
top salesforce developer skills in 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Choose the Right IT Partner for Your Business in Malaysia
Computer Software and OS of computer science of grade 11.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Transform Your Business with a Software ERP System
medical staffing services at VALiNTRY
Odoo Companies in India – Driving Business Transformation.pdf
L1 - Introduction to python Backend.pptx
Nekopoi APK 2025 free lastest update
Digital Systems & Binary Numbers (comprehensive )
Introduction Database Management System for Course Database
Design an Analysis of Algorithms I-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
Upgrade and Innovation Strategies for SAP ERP Customers
Ad

Default convention for entity framework code first

  • 1. table lists default code first conventions Default Convention For Description Schema By default, EF creates all the DB objects into the dbo schema. Table Name <Entity Class Name> + 's' 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. Primary key Name 1) Id 2) <Entity Class Name> + "Id" (case insensitive) EF will create a primary key column for the property named Id or <Entity Class Name> + "Id" (case insensitive). Foreign key property Name By default, EF will look for the foreign key property with the same name as the principal entity primary key name. If the foreign key property does not exist, then EF will create an FK column in the Db table with <Dependent Navigation Property Name> + "_" + <Principal Entity Primary Key Property Name> e.g. EF will create Grade_GradeId foreign key column in the Students table if the Student entity does not contain foreignkey property for Grade. Null column EF creates a null column for all reference type properties and nullable primitive properties e.g. string, Nullable<int>, Student, Grade (all class type properties) Not Null Column EF creates NotNull columns for Primary Key properties and non-nullable value type properties e.g. int, float, decimal, datetime etc. DB Columns order EF will create DB columns in the same order like the properties in an entity class. However, primary key columns would be moved first. Properties mapping to DB By default, all properties will map to the database. Use the [NotMapped] attribute to exclude property or class from DB mapping. Cascade delete Enabled by default for all types of relationships.
  • 2. The following table list C# data type mapped with SQL Server data type. C# Data Type Mapping to SQL Server Data Type int int string nvarchar(Max) decimal decimal(18,2) float real byte[] varbinary(Max) datetime datetime bool bit byte tinyint short smallint long bigint double float char No mapping sbyte No mapping (throws exception) object No mapping