简体   繁体   中英

How to run migration in C#.NET project?

I have project that works with SQL server. In Models directory I have migrtions files like as one:

public partial class UserData : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.confirmation_code",
                c => new
                    {
                        sys_id = c.Long(nullable: false, identity: true),
                        resource_id = c.Guid(nullable: false),
                        code = c.String(maxLength: 64),
                        user_id = c.Long(nullable: false),
                        id = c.Guid(nullable: false),
                        edit_date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.sys_id)
                .ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
                .Index(t => t.user_id);
....

For development I use VisualStudio, how to run all migration to deploy?

You should open the Nuget Management Console and type update-database command with migration name, and additional parameters if they are needed. Depending on your setup you might need to provide connection string name and/or project where they are located.

More on this: Entity Framework Code First Migrations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM