Entity Framework 6 Migration to change CLOB column to VARCHAR in Oracle

ef-migrations entity-framework entity-framework-6 oracle

Question

I am trying to change a CLOB column to VARCHAR(2000) in oracle using EF 6 migration. When EF scaffold the migration file, I have the following line of code in my Up() method:

AlterColumn("MTA.PLAN_SHEETS", "PLANSHEET_NAME", c => c.String(maxLength: 2000, unicode: false));

When I run the migration I get this error

invalid modification of columns

I know that in Oracle we cannot change a Clob to Varchar directly:
How to change a dataype CLOB TO VARCHAR2(sql)

What is the best approach to change a Clob to Varchar in Entity Framework migration?

1
2
5/23/2017 11:53:07 AM

Popular Answer

There is the same problem in probably all RDBMSs. I always use a code similar to this and I think (I'm quite sure) that this is the only way to do it.

AddColumn("MTA.PLAN_SHEETS", "TMP_COLUMN", c => c.String(maxLength: 2000, unicode: false));
Sql(@"UPDATE MTA.PLAN_SHEETS SET TMP_COLUMN = PLANSHEET_NAME");
DropColumn("MTA.PLAN_SHEETS", "PLANSHEET_NAME");
RenameColumn("MTA.PLAN_SHEETS", "TMP_COLUMN", "PLANSHEET_NAME");
1
1/20/2017 8:41:41 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow