Advertisement
Ludwiq

Migracja

Feb 4th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1.  public partial class NotesAndTags : DbMigration
  2.     {
  3.         public override void Up()
  4.         {
  5.             CreateTable(
  6.                 "dbo.Notes",
  7.                 c => new
  8.                     {
  9.                         ID = c.Int(nullable: false, identity: true),
  10.                         Content = c.String(),
  11.                         DateOfPosting = c.DateTime(nullable: false),
  12.                         OwnerName = c.String(),
  13.                     })
  14.                 .PrimaryKey(t => t.ID);
  15.            
  16.             CreateTable(
  17.                 "dbo.Tags",
  18.                 c => new
  19.                     {
  20.                         ID = c.Int(nullable: false, identity: true),
  21.                         Name = c.String(),
  22.                     })
  23.                 .PrimaryKey(t => t.ID);
  24.            
  25.             CreateTable(
  26.                 "dbo.TagsNotes",
  27.                 c => new
  28.                     {
  29.                         Tags_ID = c.Int(nullable: false),
  30.                         Notes_ID = c.Int(nullable: false),
  31.                     })
  32.                 .PrimaryKey(t => new { t.Tags_ID, t.Notes_ID })
  33.                 .ForeignKey("dbo.Tags", t => t.Tags_ID, cascadeDelete: true)
  34.                 .ForeignKey("dbo.Notes", t => t.Notes_ID, cascadeDelete: true)
  35.                 .Index(t => t.Tags_ID)
  36.                 .Index(t => t.Notes_ID);
  37.            
  38.         }
  39.        
  40.         public override void Down()
  41.         {
  42.             DropForeignKey("dbo.TagsNotes", "Notes_ID", "dbo.Notes");
  43.             DropForeignKey("dbo.TagsNotes", "Tags_ID", "dbo.Tags");
  44.             DropIndex("dbo.TagsNotes", new[] { "Notes_ID" });
  45.             DropIndex("dbo.TagsNotes", new[] { "Tags_ID" });
  46.             DropTable("dbo.TagsNotes");
  47.             DropTable("dbo.Tags");
  48.             DropTable("dbo.Notes");
  49.         }
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement