Search code examples
sql-serverentity-framework-4migrationdb2

Using Entity Framework to migrate database structure


We have a EF model of a DB2 database.

Is it possible to use this model to generate a SQL Server database? And then switch between using DB2 and SQL Server?

We were thinking that the developers could develop against a local SQL Server database.

We use EF 4.1.


Solution

  • There can be problems with the field types, if you define them for yourself. I have been doing such a thing with Sql-Oracle, and in the end, we where creating custom Attributes, like [VarcharAttribute] and configured the entities to use the correct typename in the OnModelBuilder function.

    This might not work :

    [Column(TypeName="varchar")]
    public string Data{get;set;}
    

    because for Oracle it should look like this :

    [Column(TypeName="VARCHAR2")]
    public string Data{get;set;}
    

    Also there can be other problems, for example in the sql-oracle merge a table name was over 30 characters, and it worked in sql, but didn't work in oracle, because the table name was limited to 30 characters.

    But after you fix these problems, then it will work. At the end we were able to set the provider from config file.

    So yes, it is possible, if you take care of the database differences