本文整理汇总了C#中MigrationBuilder.Sql方法的典型用法代码示例。如果您正苦于以下问题:C# MigrationBuilder.Sql方法的具体用法?C# MigrationBuilder.Sql怎么用?C# MigrationBuilder.Sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MigrationBuilder
的用法示例。
在下文中一共展示了MigrationBuilder.Sql方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
if (ActiveProvider == "Microsoft.EntityFrameworkCore.SqlServer")
{
migrationBuilder.Sql("CREATE DATABASE TransactionSuppressed", suppressTransaction: true);
migrationBuilder.Sql("DROP DATABASE TransactionSuppressed", suppressTransaction: true);
}
}
示例2: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("DROP VIEW HierarchyPosts");
migrationBuilder.Sql("DROP TRIGGER trigger_Posts_LastChangedDate");
migrationBuilder.DropTable("PostRevisions");
migrationBuilder.DropTable("Votes");
migrationBuilder.DropTable("RoleClaims");
migrationBuilder.DropTable("UserClaims");
migrationBuilder.DropTable("UserLogins");
migrationBuilder.DropTable("UserRoles");
migrationBuilder.DropTable("Posts");
migrationBuilder.DropTable("Roles");
migrationBuilder.DropTable("Forums");
migrationBuilder.DropTable("Users");
}
示例3: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"Alter view HierarchyPosts as
WITH cte ( Id, ParentPostId, Depth, RootId )
AS ( SELECT Id,
ReplyToPostId,
0 as TheLevel,
Id as RootId
FROM posts
where ReplyToPostId is null
And IsDeleted = 0
UNION ALL
SELECT pn.Id,
pn.ReplyToPostId,
p1.Depth +1,
p1.RootId
FROM Posts pn
INNER JOIN cte AS p1 on p1.Id = pn.ReplyToPostId
Where pn.IsDeleted = 0
)
select cte.Id as PostId, ReplyToPostId, Depth, ForumId, LastChangedDate, PublishDate, Title, Body, IsModified, U.UserName, u.Id as UserId, RootId, IsDeleted, IsImportantReply
from cte
INNER JOIN POSTS P ON CTE.ID = P.ID
INNER JOIN USERS u ON U.id = p.UserId");
}
示例4: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CourseAssignment_Instructor_InstructorID",
table: "CourseAssignment");
migrationBuilder.DropForeignKey(
name: "FK_Department_Instructor_InstructorID",
table: "Department");
migrationBuilder.DropForeignKey(
name: "FK_Enrollment_Student_StudentID",
table: "Enrollment");
migrationBuilder.DropIndex(name: "IX_Enrollment_StudentID", table: "Enrollment");
migrationBuilder.RenameTable(name: "Instructor", newName: "Person");
migrationBuilder.AddColumn<DateTime>(name: "EnrollmentDate", table: "Person", nullable: true);
migrationBuilder.AddColumn<string>(name: "Discriminator", table: "Person", nullable: false, maxLength: 128, defaultValue: "Instructor");
migrationBuilder.AlterColumn<DateTime>(name: "HireDate", table: "Person", nullable: true);
migrationBuilder.AddColumn<int>(name: "OldId", table: "Person", nullable: true);
// Copy existing Student data into new Person table.
migrationBuilder.Sql("INSERT INTO dbo.Person (LastName, FirstName, HireDate, EnrollmentDate, Discriminator, OldId) SELECT LastName, FirstName, null AS HireDate, EnrollmentDate, 'Student' AS Discriminator, ID AS OldId FROM dbo.Student");
// Fix up existing relationships to match new PK's.
migrationBuilder.Sql("UPDATE dbo.Enrollment SET StudentId = (SELECT ID FROM dbo.Person WHERE OldId = Enrollment.StudentId AND Discriminator = 'Student')");
// Remove temporary key
migrationBuilder.DropColumn(name: "OldID", table: "Person");
migrationBuilder.DropTable(
name: "Student");
migrationBuilder.AddForeignKey(
name: "FK_Enrollment_Person_StudentID",
table: "Enrollment",
column: "StudentID",
principalTable: "Person",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
migrationBuilder.CreateIndex(
name: "IX_Enrollment_StudentID",
table: "Enrollment",
column: "StudentID");
}
示例5: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"IF OBJECT_ID(N'[dbo].[SearchProducts]') IS NULL
EXEC('CREATE FUNCTION [dbo].[SearchProducts] ( @term nvarchar(200) )
RETURNS TABLE
AS
RETURN
(
SELECT *
FROM dbo.Product
WHERE Product.DisplayName LIKE ''%'' + @term + ''%''
OR Product.Description LIKE ''%'' + @term + ''%''
)')");
}
示例6: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"Alter view HierarchyPosts as
WITH Cte (Id, Parentpostid, Depth, Rootid) AS
(SELECT Id,
Replytopostid,
0 AS Thelevel,
Id AS Rootid
FROM Posts
WHERE Replytopostid IS NULL
AND Isdeleted = 0
UNION ALL SELECT Pn.Id,
Pn.Replytopostid,
P1.Depth +1,
P1.Rootid
FROM Posts Pn
INNER JOIN Cte AS P1 ON P1.Id = Pn.Replytopostid
WHERE Pn.Isdeleted = 0)
SELECT Cte.Id AS Postid,
ReplyToPostId,
Depth,
ForumId,
LastChangedDate,
PublishDate,
Title,
Body,
IsModified,
U.UserName,
U.Id,
UserId,
RootId,
IsDeleted,
IsImportantReply,
Views,
(SELECT Count(1)
FROM Userreviews Ur
WHERE Ur.Touserid = P.Userid
AND Ur.Votetype = 1
AND Ur.IsDeleted = 0) AS PositiveReviewsScore,
(SELECT Count(1)
FROM Userreviews Ur
WHERE Ur.Touserid = P.Userid
AND Ur.Votetype = 2
AND Ur.IsDeleted = 0) AS NegativeReviewsScore
FROM Cte
INNER JOIN Posts P ON Cte.Id = P.Id
INNER JOIN Users U ON U.Id = P.Userid");
migrationBuilder.DropColumn(name: "IsOriginal", table: "Posts");
migrationBuilder.DropColumn(name: "SourceLink", table: "Posts");
}
示例7: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "TimeZoneId",
table: "Event",
nullable: false,
defaultValue: "Central Standard Time");
//Set the TimeZoneID for existing events based on the TimeZoneID of the parent campaign
migrationBuilder.Sql(
@"UPDATE e SET e.[TimeZoneID] = c.[TimeZoneID]
FROM [Event] e
INNER JOIN Campaign c ON c.Id = e.CampaignId
");
}
示例8: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"Alter view HierarchyPosts as
WITH Cte (Id, Parentpostid, Depth, Rootid) AS
(SELECT Id,
Replytopostid,
0 AS Thelevel,
Id AS Rootid
FROM Posts
WHERE Replytopostid IS NULL
AND Isdeleted = 0
UNION ALL SELECT Pn.Id,
Pn.Replytopostid,
P1.Depth +1,
P1.Rootid
FROM Posts Pn
INNER JOIN Cte AS P1 ON P1.Id = Pn.Replytopostid
WHERE Pn.Isdeleted = 0)
SELECT Cte.Id AS Postid,
Replytopostid,
Depth,
Forumid,
Lastchangeddate,
Publishdate,
Title,
Body,
Ismodified,
U.Username,
U.Id,
Userid,
Rootid,
Isdeleted,
Isimportantreply,
(SELECT Count(1)
FROM Userreviews Ur
WHERE Ur.Touserid = P.Userid
AND Ur.Votetype = 1
AND Ur.IsDeleted = 0) AS PositiveReviewsScore,
(SELECT Count(1)
FROM Userreviews Ur
WHERE Ur.Touserid = P.Userid
AND Ur.Votetype = 2
AND Ur.IsDeleted = 0) AS NegativeReviewsScore
FROM Cte
INNER JOIN Posts P ON Cte.Id = P.Id
INNER JOIN Users U ON U.Id = P.Userid");
}
示例9: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Activity_Campaign_CampaignId", table: "Activity");
migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Activity_ActivityId", table: "ActivitySkill");
migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Skill_SkillId", table: "ActivitySkill");
migrationBuilder.DropForeignKey(name: "FK_Campaign_Tenant_ManagingTenantId", table: "Campaign");
migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Campaign_CampaignId", table: "CampaignContact");
migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Contact_ContactId", table: "CampaignContact");
migrationBuilder.DropForeignKey(name: "FK_TaskSkill_Skill_SkillId", table: "TaskSkill");
migrationBuilder.DropForeignKey(name: "FK_TaskSkill_AllReadyTask_TaskId", table: "TaskSkill");
migrationBuilder.DropForeignKey(name: "FK_TenantContact_Contact_ContactId", table: "TenantContact");
migrationBuilder.DropForeignKey(name: "FK_TenantContact_Tenant_TenantId", table: "TenantContact");
migrationBuilder.DropForeignKey(name: "FK_UserSkill_Skill_SkillId", table: "UserSkill");
migrationBuilder.DropForeignKey(name: "FK_UserSkill_ApplicationUser_UserId", table: "UserSkill");
migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId", table: "AspNetRoleClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId", table: "AspNetUserClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId", table: "AspNetUserLogins");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_IdentityRole_RoleId", table: "AspNetUserRoles");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_ApplicationUser_UserId", table: "AspNetUserRoles");
migrationBuilder.AddColumn<DateTimeOffset>(
name: "EndDateTime",
table: "Activity",
nullable: false,
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
migrationBuilder.AddColumn<DateTimeOffset>(
name: "StartDateTime",
table: "Activity",
nullable: false,
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
migrationBuilder.AddForeignKey(
name: "FK_Activity_Campaign_CampaignId",
table: "Activity",
column: "CampaignId",
principalTable: "Campaign",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.Sql("UPDATE Activity SET StartDateTime = StartDateTimeUtc, EndDateTime = EndDateTimeUtc");
migrationBuilder.DropColumn(name: "EndDateTimeUtc", table: "Activity");
migrationBuilder.DropColumn(name: "StartDateTimeUtc", table: "Activity");
migrationBuilder.AddForeignKey(
name: "FK_ActivitySkill_Activity_ActivityId",
table: "ActivitySkill",
column: "ActivityId",
principalTable: "Activity",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_ActivitySkill_Skill_SkillId",
table: "ActivitySkill",
column: "SkillId",
principalTable: "Skill",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Campaign_Tenant_ManagingTenantId",
table: "Campaign",
column: "ManagingTenantId",
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_CampaignContact_Campaign_CampaignId",
table: "CampaignContact",
column: "CampaignId",
principalTable: "Campaign",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_CampaignContact_Contact_ContactId",
table: "CampaignContact",
column: "ContactId",
principalTable: "Contact",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_TaskSkill_Skill_SkillId",
table: "TaskSkill",
column: "SkillId",
principalTable: "Skill",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_TaskSkill_AllReadyTask_TaskId",
table: "TaskSkill",
column: "TaskId",
principalTable: "AllReadyTask",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_TenantContact_Contact_ContactId",
table: "TenantContact",
column: "ContactId",
principalTable: "Contact",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_TenantContact_Tenant_TenantId",
table: "TenantContact",
column: "TenantId",
//.........这里部分代码省略.........
示例10: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(nullable: false, type: "nvarchar(450)"),
ConcurrencyStamp = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true, type: "nvarchar(256)"),
NormalizedName = table.Column<string>(nullable: true, type: "nvarchar(256)")
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityRole", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(nullable: false, type: "nvarchar(450)"),
AccessFailedCount = table.Column<int>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
Email = table.Column<string>(nullable: true, type: "nvarchar(256)"),
EmailConfirmed = table.Column<bool>(nullable: false),
LockoutEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
NormalizedEmail = table.Column<string>(nullable: true, type: "nvarchar(256)"),
NormalizedUserName = table.Column<string>(nullable: true, type: "nvarchar(256)"),
PasswordHash = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
SecurityStamp = table.Column<string>(nullable: true),
TwoFactorEnabled = table.Column<bool>(nullable: false),
UserName = table.Column<string>(nullable: true, type: "nvarchar(256)")
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityUser", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(nullable: true),
RoleId = table.Column<string>(nullable: true, type: "nvarchar(450)")
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityRoleClaim<string>", x => x.Id);
table.ForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(nullable: true),
UserId = table.Column<string>(nullable: true, type: "nvarchar(450)")
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityUserClaim<string>", x => x.Id);
table.ForeignKey(
name: "FK_IdentityUserClaim<string>_IdentityUser_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(nullable: false, type: "nvarchar(450)"),
ProviderKey = table.Column<string>(nullable: false, type: "nvarchar(450)"),
ProviderDisplayName = table.Column<string>(nullable: true),
UserId = table.Column<string>(nullable: true, type: "nvarchar(450)")
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityUserLogin<string>", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_IdentityUserLogin<string>_IdentityUser_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
//.........这里部分代码省略.........
示例11: Sql_adds_operation
public void Sql_adds_operation()
{
var builder = new MigrationBuilder();
builder.Sql("MySql");
Assert.Equal(1, builder.Operations.Count);
Assert.IsType<SqlOperation>(builder.Operations[0]);
var operation = (SqlOperation)builder.Operations[0];
Assert.Equal("MySql", operation.Sql);
}
示例12: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Activity_Campaign_CampaignId", table: "Activity");
migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Activity_ActivityId", table: "ActivitySkill");
migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Skill_SkillId", table: "ActivitySkill");
migrationBuilder.DropForeignKey(name: "FK_Campaign_Tenant_ManagingTenantId", table: "Campaign");
migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Campaign_CampaignId", table: "CampaignContact");
migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Contact_ContactId", table: "CampaignContact");
migrationBuilder.DropForeignKey(name: "FK_TaskSkill_Skill_SkillId", table: "TaskSkill");
migrationBuilder.DropForeignKey(name: "FK_TaskSkill_AllReadyTask_TaskId", table: "TaskSkill");
migrationBuilder.DropForeignKey(name: "FK_TenantContact_Contact_ContactId", table: "TenantContact");
migrationBuilder.DropForeignKey(name: "FK_TenantContact_Tenant_TenantId", table: "TenantContact");
migrationBuilder.DropForeignKey(name: "FK_UserSkill_Skill_SkillId", table: "UserSkill");
migrationBuilder.DropForeignKey(name: "FK_UserSkill_ApplicationUser_UserId", table: "UserSkill");
migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId", table: "AspNetRoleClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId", table: "AspNetUserClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId", table: "AspNetUserLogins");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_IdentityRole_RoleId", table: "AspNetUserRoles");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_ApplicationUser_UserId", table: "AspNetUserRoles");
migrationBuilder.AddColumn<DateTimeOffset>(
name: "EndDateTimeUtc",
table: "AllReadyTask",
nullable: true);
migrationBuilder.AddColumn<DateTimeOffset>(
name: "StartDateTimeUtc",
table: "AllReadyTask",
nullable: true);
migrationBuilder.Sql("UPDATE AllReadyTask SET StartDateTimeUtc = StartDateTime, EndDateTimeUtc = EndDateTime");
migrationBuilder.DropColumn(name: "EndDateTime", table: "AllReadyTask");
migrationBuilder.DropColumn(name: "StartDateTime", table: "AllReadyTask");
migrationBuilder.AddForeignKey(
name: "FK_Activity_Campaign_CampaignId",
table: "Activity",
column: "CampaignId",
principalTable: "Campaign",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_ActivitySkill_Activity_ActivityId",
table: "ActivitySkill",
column: "ActivityId",
principalTable: "Activity",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_ActivitySkill_Skill_SkillId",
table: "ActivitySkill",
column: "SkillId",
principalTable: "Skill",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Campaign_Tenant_ManagingTenantId",
table: "Campaign",
column: "ManagingTenantId",
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_CampaignContact_Campaign_CampaignId",
table: "CampaignContact",
column: "CampaignId",
principalTable: "Campaign",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_CampaignContact_Contact_ContactId",
table: "CampaignContact",
column: "ContactId",
principalTable: "Contact",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_TaskSkill_Skill_SkillId",
table: "TaskSkill",
column: "SkillId",
principalTable: "Skill",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_TaskSkill_AllReadyTask_TaskId",
table: "TaskSkill",
column: "TaskId",
principalTable: "AllReadyTask",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_TenantContact_Contact_ContactId",
table: "TenantContact",
column: "ContactId",
principalTable: "Contact",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_TenantContact_Tenant_TenantId",
table: "TenantContact",
column: "TenantId",
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
//.........这里部分代码省略.........
示例13: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Instructor",
columns: table => new
{
ID = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
FirstName = table.Column<string>(maxLength: 50, nullable: false),
HireDate = table.Column<DateTime>(nullable: false),
LastName = table.Column<string>(maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Instructor", x => x.ID);
});
migrationBuilder.CreateTable(
name: "CourseAssignment",
columns: table => new
{
CourseID = table.Column<int>(nullable: false),
InstructorID = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CourseAssignment", x => new { x.CourseID, x.InstructorID });
table.ForeignKey(
name: "FK_CourseAssignment_Course_CourseID",
column: x => x.CourseID,
principalTable: "Course",
principalColumn: "CourseID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CourseAssignment_Instructor_InstructorID",
column: x => x.InstructorID,
principalTable: "Instructor",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Department",
columns: table => new
{
DepartmentID = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Budget = table.Column<decimal>(type: "money", nullable: false),
InstructorID = table.Column<int>(nullable: true),
Name = table.Column<string>(maxLength: 50, nullable: true),
StartDate = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Department", x => x.DepartmentID);
table.ForeignKey(
name: "FK_Department_Instructor_InstructorID",
column: x => x.InstructorID,
principalTable: "Instructor",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "OfficeAssignment",
columns: table => new
{
InstructorID = table.Column<int>(nullable: false),
Location = table.Column<string>(maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OfficeAssignment", x => x.InstructorID);
table.ForeignKey(
name: "FK_OfficeAssignment_Instructor_InstructorID",
column: x => x.InstructorID,
principalTable: "Instructor",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
#region snippet_DefaultDepartment
migrationBuilder.Sql("INSERT INTO dbo.Department (Name, Budget, StartDate) VALUES ('Temp', 0.00, GETDATE())");
// Default value for FK points to department created above, with
// defaultValue changed to 1 in following AddColumn statement.
migrationBuilder.AddColumn<int>(
name: "DepartmentID",
table: "Course",
nullable: false,
defaultValue: 1);
//migrationBuilder.AddColumn<int>(
// name: "DepartmentID",
// table: "Course",
// nullable: false,
// defaultValue: 0);
#endregion
migrationBuilder.AlterColumn<string>(
//.........这里部分代码省略.........
示例14: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable("Users", table => new
{
Id = table.Column<string>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
Email = table.Column<string>(nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
LockoutEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
NormalizedEmail = table.Column<string>(nullable: true),
NormalizedUserName = table.Column<string>(nullable: true),
PasswordHash = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
SecurityStamp = table.Column<string>(nullable: true),
TwoFactorEnabled = table.Column<bool>(nullable: false),
UserName = table.Column<string>(nullable: true)
},
constraints: table => { table.PrimaryKey("PK_ApplicationUser", x => x.Id); });
migrationBuilder.CreateTable("Forums", table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Description = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true)
},
constraints: table => { table.PrimaryKey("PK_Forum", x => x.Id); });
migrationBuilder.CreateTable("Roles", table => new
{
Id = table.Column<string>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
NormalizedName = table.Column<string>(nullable: true)
},
constraints: table => { table.PrimaryKey("PK_IdentityRole", x => x.Id); });
migrationBuilder.CreateTable("UserClaims", table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(nullable: true),
UserId = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityUserClaim<string>", x => x.Id);
table.ForeignKey("FK_IdentityUserClaim<string>_ApplicationUser_UserId", x => x.UserId, "Users", "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable("UserLogins", table => new
{
LoginProvider = table.Column<string>(nullable: false),
ProviderKey = table.Column<string>(nullable: false),
ProviderDisplayName = table.Column<string>(nullable: true),
UserId = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_IdentityUserLogin<string>", x => new {x.LoginProvider, x.ProviderKey});
table.ForeignKey("FK_IdentityUserLogin<string>_ApplicationUser_UserId", x => x.UserId, "Users", "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable("Posts", table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Body = table.Column<string>(nullable: true),
ForumId = table.Column<int>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
IsImportantReply = table.Column<bool>(nullable: false),
IsLocked = table.Column<bool>(nullable: false),
IsModified = table.Column<bool>(nullable: false),
LastChangedDate = table.Column<DateTime>(nullable: true),
LockReason = table.Column<string>(nullable: true),
LockingUserId = table.Column<string>(nullable: true),
PostType = table.Column<int>(nullable: false),
PublishDate = table.Column<DateTime>(nullable: false, defaultValueSql: "getutcdate()"),
ReplyToPostId = table.Column<int>(nullable: true),
Score = table.Column<int>(nullable: false),
Title = table.Column<string>(nullable: false),
UserId = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Post", x => x.Id);
table.ForeignKey("FK_Post_Forum_ForumId", x => x.ForumId, "Forums", "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey("FK_Post_ApplicationUser_LockingUserId", x => x.LockingUserId, "Users", "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey("FK_Post_Post_ReplyToPostId", x => x.ReplyToPostId, "Posts", "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey("FK_Post_ApplicationUser_UserId", x => x.UserId, "Users", "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable("RoleClaims", table => new
{
Id = table.Column<int>(nullable: false)
//.........这里部分代码省略.........