postgresql, efcore, fluent api mappings
Just started playing around with posgress and efcore. The type mapping for fluent api is different from sql server. The reference for mappings I believe is here: https://www.npgsql.org/doc/types/basic.html#write-mappings
My main question is, when I'm writing
.HasColumnType("") should follow the values in the column "PostgreSQL type"? or is "NpgsqlDbType" is valid too?
meaning for nvarchar => .HasColumnType("character varying") or .HasColumnType("Varchar")
6 Replies
Those are the default mappings, no need to specify the column type explicitly
A
long property will map to a BIGINT column without you having to specify .HasColumnType("BIGINT")My advice with EF is to let at much as possible be done automatically by convention.
I understand that efcore automatically infers from the model types, I just wanna be comfortable with the fluent api, and get familiar with especially in case which cannot be inferred. for instance the biggest amount of strings in sql server is
.HasColumnType("navarchar(max)") , whereas posgres is.HasColumnType("text") or oracle is clob or whatever they use in oracle land.
so I'm wondering as the reference, and when in doubt, should I stick to "PostgreSql type" ?.HasColumnType("navarchar(max)")
Incorrect.
.HasMaxLength(-1) (which is default on strings)
leave it default, your dev cycle should be
1. Generate migration
2. Check migration
3. Make changes to the configuration as needed,
4. RepeatHasColumnType takes whatever name for the type you would use in sql.appreciate all your answers, thank you