Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core - Migration Fluent API HasColumnType

I'm using .NET CORE 2.2 and EF CORE for SQLSERVER and PostgreSQL.

In postgresql doesn't exists varchar(max) or varchar(-1) like on SQLSERVER,in postgresql the data type is TEXT.

On this column, I need it to be varchar(max) for the SQL server and text for Postgres., How can it be done?

That migration needs to be understood by each provider.

I appreciate your help.

builder.Property(x => x.Foo).HasColumnType("varchar(-1)");

sorry, my English is not so good.

like image 305
Paulo Alexandre Avatar asked Oct 16 '22 14:10

Paulo Alexandre


1 Answers

The default ColumnType of string will automatically map to the Max length field. so be leaving off the column type you should get what you want.

builder.Property(x => x.Foo)

like image 98
Richard Hubley Avatar answered Oct 20 '22 06:10

Richard Hubley