Skip to content

This repository contains a custom migration operation for entity framework 6 for creating and dropping a CHECK CONSTRAINTS and DEFAULT CONSTRAINTS.

Notifications You must be signed in to change notification settings

ferpaz/ef-custommigrations

 
 

Repository files navigation

##Entity Framework 6 - Custom migration operations

This repository contains a custom migration operation for entity framework 6 for creating and dropping a CHECK CONSTRAINTS and DEFAULT CONSTRAINTS.

Usage

for Check Constraint

namespace EFCustomMigrationOperations.Sample.Migrations
{
    public partial class AddCheckConstraint : DbMigration
    {
        public override void Up()
        {
            this.CreateCheckConstraint("Products", "SKU", "SKU LIKE '[A-Z][A-Z]-[0-9][0-9]%'");
        }
        
        public override void Down()
        {
            this.DropCheckConstraint("Products", "CK_Products_SKU");
        }
    }
}

for Default Constraint

namespace EFCustomMigrationOperations.Sample.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class AddDefaultContraint : DbMigration
    {
        public override void Up()
        {
            this.CreateDefaultConstraint("Products", "InStock", "1");
        }
    
        public override void Down()
        {
            this.DropDefaultConstraint("Products", "DF_Products_InStock");
        }
    }
}

For more details, look at this article.

About

This repository contains a custom migration operation for entity framework 6 for creating and dropping a CHECK CONSTRAINTS and DEFAULT CONSTRAINTS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%