Page 1 of 1

How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Posted: Wed 16 Oct 2013 23:17
by John Liu
RoMiller created a post on how to write an custom code first migration operation using sql server provider.
http://romiller.com/2013/02/27/ef6-writ ... perations/
Following the example, I wrote my own code first migration operations that work great with sql server provider.
I need to make those migration operations work with dotConnect for oracle. I just wonder if someone can write an sample on how to extend OracleEntityMigrationSqlGenerator?
public class MyOracleMigrationSqlGenerator : OracleEntityMigrationSqlGenerator
{
public override IEnumerable<MigrationStatement> Generate(IEnumerable<System.Data.Entity.Migrations.Model.MigrationOperation> migrationOperations, string providerManifestToken)
{
}
}
thanks
JL

Re: How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Posted: Thu 17 Oct 2013 10:21
by Shalex
Examples of registering OracleEntityMigrationSqlGenerator are available at http://blogs.devart.com/dotconnect/enti ... #Generator.

If you are working with EF6, an additional Entity Framework provider registration is required: http://blogs.devart.com/dotconnect/enti ... gistration.

Does it help?

Re: How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Posted: Thu 17 Oct 2013 14:20
by John Liu
Thank you for your reply! I know how to register my MigrationSqlGenerator. My question is how to write a method to override the Generate method in OracleEntityMigrationSqlGenerator. If you could give me some sample code that would be great. I wrote one for the sql server provider based on RoMiller's post. I need to write one to use dotConnect for oracle. I'm using EF6 RC1 with dotConnect 7.9.322.6
thanks
JL

Re: How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Posted: Tue 22 Oct 2013 15:02
by Shalex
OracleEntityMigrationSqlGenerator does not include void Generate(MigrationOperation migrationOperation) method.

Please override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken):

Code: Select all

using System.Collections.Generic;
using System.Data.Entity.Migrations.Model;
using System.Data.Entity.Migrations.Sql;
using System.Linq;
using Devart.Common.Entity;
using Devart.Common.Entity.Migrations;
using Devart.Data.Oracle.Entity.Migrations;
using MyApplication.ExtendingMigrations.Migrations;
using System.Text;
 
namespace MyApplication{
    public class MyOracleMigrationSqlGenerator : OracleEntityMigrationSqlGenerator  {
 
        public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken) {

            List<MigrationOperation> modifiedOperations = migrationOperations.ToList();

            for (int i = 0; i < modifiedOperations.Count; i++) {
                MigrationOperation currentItem = modifiedOperations[i];
                GrantPermissionOperation myMigration = currentItem as GrantPermissionOperation;
                if (myMigration != null) {
                    StringBuilder sql = new StringBuilder();
                    sql.Append("...");
                    sql.Append("...");
                    sql.Append("...");
                    SqlOperation sqlOperation = new SqlOperation(sql.ToString());
                    modifiedOperations[i] = sqlOperation;
                }
            }

            return base.Generate(modifiedOperations, providerManifestToken);  
        }
    }
}

Re: How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Posted: Wed 23 Oct 2013 21:40
by John Liu
That's what I needed! thanks
JL