Friday, January 9, 2015

EF- To Set Default Values in Database Columns using CF Migrations

 
1..................... 
namespace EFCF.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class userregisteredon : DbMigration
    {
        public override void Up()
        {
            AlterColumn("User""RegisteredOn", c => c.DateTime(nullable: false, defaultValueSql: "GetDate()"));
        }
        
        public override void Down()
        {
            AlterColumn("User""RegisteredOn", c => c.DateTime(nullable: true, defaultValue: null));
        }
    }
}
 
 
2................. 
 public partial class blogDescLenthChanged : DbMigration
    {
        public override void Up()
        {
            AlterColumn("dbo.Category""IsActive", c => c.Boolean(nullable: false, defaultValue :true));
        }
        
        public override void Down()
        {
            AlterColumn("dbo.Category""IsActive", c => c.Boolean(nullable: true, defaultValue: false));
        }
    } 

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More