C
C#2mo ago
AlisterKB

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")
No description
6 Replies
Angius
Angius2mo ago
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")
jcotton42
jcotton422mo ago
My advice with EF is to let at much as possible be done automatically by convention.
AlisterKB
AlisterKBOP2mo ago
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" ?
Pobiega
Pobiega2mo ago
.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. Repeat
jcotton42
jcotton422mo ago
HasColumnType takes whatever name for the type you would use in sql.
AlisterKB
AlisterKBOP2mo ago
appreciate all your answers, thank you

Did you find this page helpful?