Adding A Column using AlterTable method

Topics: General, Troubleshooting
May 31, 2011 at 7:38 AM

Dear All

 

i try to add a column to a table using the below method

 

public int UpdateFrom2()
       {
         SchemaBuilder.AlterTable("PropertyBookingEntryRecord", table => table
         .AddColumn("PropertyCartItemDetailRecord_id ", DbType.Int32)
                );
          return 2;
         }

the column is added successfully to a table but its taking no value. every time its showing null.

 

but when i delete all the AppData and restarted the project at time it worked.

 

can u plz help me out as every time i want to add a column to a table i unnecessarily need to delete all the data and restart the projet again

May 31, 2011 at 10:28 AM

I ran into this problem quite recently. I raised an issue here: http://orchard.codeplex.com/workitem/17888 - please vote for it!

May 31, 2011 at 10:29 AM

BTW; you should return 3 from that UpdateFrom2 method. The number needs to increment with each migration.

Jun 1, 2011 at 8:07 AM

Dear All

i try to add a column to a table using the below method

public int UpdateFrom2()
{
SchemaBuilder.AlterTable("PropertyBookingEntryRecord", table => table
.AddColumn("PropertyCartItemDetailRecord_id ", DbType.Int32)
);
return 3;
}

the column is added successfully to a table but its taking no value. every time its showing null.

but when i delete all the AppData and restarted the project at time it worked.

can u plz help me out as every time i want to add a column to a table i unnecessarily need to delete all the data and restart the projet again

Jun 1, 2011 at 10:14 AM

Hi mourice, I misunderstood your post - you're not using WithDefault. So the new column is presumably null because you're not setting a value? Or can you show the code where you attempt to assign a record to PropertyCartItemDetailRecord?

Jun 2, 2011 at 5:32 AM

  i am having this table

 

               SchemaBuilder.CreateTable("PropertyBookingEntryRecord", table => table
                .Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
                .Column("PropertyBookingRecord_Id", DbType.Int32)
                .Column("CartItem_Id", DbType.Int32)
                .Column("CheckInOn", DbType.DateTime)
                .Column("CheckOutOn", DbType.DateTime)
                .Column("NoOfAdultPassangers", DbType.Int32)
                .Column("NoOfChildren", DbType.Int32)
                .Column("NoOfDays", DbType.Int32)
                .Column("Property_id", DbType.Int32)

 

 

and i want to add a column PropertyCartItemDetailRecord_Id So i m Writing

 

public int UpdateFrom1()
         {
           SchemaBuilder.AlterTable("PropertyBookingEntryRecord", table => table
           .AddColumn("PropertyCartItemDetailRecord_Id", DbType.Int32)
                );
           return 2;
         }

is it the correct way. or i am doing something wrong.

To this PropertyCartItemDetailRecord_Id column i am passing a value in my controller part. but when i am Checking in LINQPad its Showing Null.

and when i just add the column to the above table as  .Column("PropertyCartItemDetailRecord_Id", DbType.Int32)  and after Deleting the Appdata and restarting the project its working fine.

 

 

 

 

Jun 2, 2011 at 10:13 AM

mourice - that's the same code you already pasted twice. Can you paste the code where you are setting the value, i.e. your controller code? All the above is fine.