Practice Management Book

http://www.fpnotebook.com/

Asp.Net Entity Framework

Aka: Asp.Net Entity Framework
  1. 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"
  2. 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')")

You are currently viewing the original 'fpnotebook.com\legacy' version of this website. Internet Explorer 8.0 and older will automatically be redirected to this legacy version.

If you are using a modern web browser, you may instead navigate to the newer desktop version of fpnotebook. Another, mobile version is also available which should function on both newer and older web browsers.

Please Contact Me as you run across problems with any of these versions on the website.

Navigation Tree