Computer

Asp.Net Entity Framework

search

Asp.Net Entity Framework

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