Computer
Asp.Net Entity Framework
search
Asp.Net Entity Framework
Precautions
Non-Medical
Not for Medical Care
The author uses several software packages and programming languages to develop FPnotebook content
For convenience, a dozen pages in FPNotebook are dedicated to quick notes on content creation
Approach
Code First
Precautions
Avoid changing database object class names (breaks the migrations)
If this occurs, see corrupted database below
Starting with asp.net mvc project with identity
Open Package Manager (Alt-"/.") and select correct default project
Type "Update-Database"
If at non-powershell command prompt, type "dotnet ef database update"
Subsequent migrations
Open Package Manager (Alt-"/.") and select correct default project
Type "Add-Migration MIGRATIONTITLE"
Type "Update-Database"
Reverse migration before update-database
Remove-Migration
Classes
Foreign keys
Set both an object property AND id property of the included object
Example: NOTE class should have both a USER and USERID property
Corrupted database
Precaution: Eliminates all data in the database (use this method only in development)
Delete the entire database in sql server object explorer
Delete all the migrations in the data directory migrations folder
Includes deleting the default migration for identity (0000..._CreateIdentitySchema.cs)
Includes deleting ApplicationDbContextModelSnapshot.cs
Re-run migrations
Update-Database (uses the default identity migration)
Type "Add-Migration MIGRATIONTITLE" (includes all other custom database dbsets)
Type "Update-Database"
Approach
Seed Data
Sql script technique
Create migration
Add-Migration POPULATE_TABLE_NAME
Create sql script into generate Up method
Sql("Insert into TABLENAME(FIELDNAME) values ('dataitem')")
Type your search phrase here