Ef Aspnet Cheat Sheet
Ef Aspnet Cheat Sheet
Create Model
Documentation...
Consider conventions
Not nullable CLR types (e.g. decimal , int , bool ) -> required
Default maximum length is provider-specific. Example: SQL Server strings -> nvarchar(max)
Shadow properties will be auto-created in the DB for foreign keys if no foreign key property is found in
the dependent class.
Index is created for each property that is used as a foreign key
Name of the DbSet<TEntity> property -> table name
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\dev;Database=AddressBook;Trusted_Connection=True"
}
}
...
}
Create a DbContext
Documentation...
DbContextOptions in Constructor:
Query Data
Documentation
Task Operation
Filter Where
Saving Data
Documentation
Task Operation
Save SaveChangesAsync
Transactions:
Manage DB Schema
Documentation
Add Migration: dotnet ef migrations add <MigrationName>
Update target database: dotnet ef database update
Remove last Migration: dotnet ef migrations remove
Generate SQL script from Migrations: dotnet ef migrations script