Type changes on migration

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
dgunseli
Posts: 2
Joined: Tue 28 Apr 2015 10:44

Type changes on migration

Post by dgunseli » Thu 16 Dec 2021 10:45

Hello all,

We are switching to Dotconnect for PostgreSQL from another provider (NpgSQL). We already have a live environment which built by migrations. After switching to Dotconnect for PostgreSQL migrations starts to generate type changes for existing entities like using varchar data type instead of text. It causes problems for migrations, especially for live production environment.

Now, we are curious about if there is a way to specify target data type for all specific data types. Instead of setting all entity fields with data annotation we want to use a specific database type for a data type (for example, text for all string fields)

Regards

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

Re: Type changes on migration

Post by Shalex » Mon 20 Dec 2021 17:53

Please specify the version of Entity Framework you are working with (e.g.: EF 6, EF Core 5, etc).

With EF 6, try using conversion:

Code: Select all

public class MyContext : DbContext {
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
 
      modelBuilder
        .Properties()
        .Where(p => p.PropertyType == typeof(string))
        .Configure(p => p.HasColumnType("text"));
    }
 
    // ...
  }

Post Reply