How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
John Liu
Posts: 61
Joined: Wed 14 Nov 2012 20:58

How to write custom code first migration operation use OracleEntityMigrationSqlGenerator

Post by John Liu » Wed 16 Oct 2013 23:17

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Thu 17 Oct 2013 10:21

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?

John Liu
Posts: 61
Joined: Wed 14 Nov 2012 20:58

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

Post by John Liu » Thu 17 Oct 2013 14:20

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Tue 22 Oct 2013 15:02

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);  
        }
    }
}

John Liu
Posts: 61
Joined: Wed 14 Nov 2012 20:58

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

Post by John Liu » Wed 23 Oct 2013 21:40

That's what I needed! thanks
JL

Post Reply