1.3.4.Seeding the database
--
1.After we add a new class and add-migration and update-database, we got a empty table, now we use migration to insert value to table, Type:
`add-migration populateMembershipTypes`
2.Modify the file generated in ~/Migrations, type some SQL statements:
namespace Vidly2.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class populateMemnershipTypes : DbMigration
{
public override void Up()
{
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonth, DiscountRate) VALUES (1, 0, 0, 0)");
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonth, DiscountRate) VALUES (2, 30, 1, 10)");
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonth, DiscountRate) VALUES (3, 90, 3, 15)");
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonth, DiscountRate) VALUES (4, 300, 12, 20)");
}
public override void Down()
{
}
}
}
3.Update database:
`update-database`
Last updated
Was this helpful?