C
C#2y ago
YazanSh

❔ Npgsql with EF Core - column "status" is of type status_enum but expression is of type integer

Hello people, I am using Postgres DB with the .Net Core 6 Web App, I am using the DB First approach and I am setting the configurations of the db context in the startup file. I saw on the PostgreSQL documentation that we can map the enums using the datasourceBuilder https://www.npgsql.org/doc/types/enums_and_composites.html?tabs=datasource Unfortunately , I defined an enum called Status that has the same values as the Db status_enum values, and tried to set the datasourceBuilder in the dbContextBuilder, but didn't work! I used the obsolete approach (the global mapping) that uses a static constructor and uses the GlobalTypeMapper, it worked well ! Can you please advise on this, is it fine to keep using this obsolete approach ? and another thing , when I used the datasourceBuilder, I didn't use the "using" and the "await" because my ConfigureServices method is not async. (await using var dataSource = dataSourceBuilder.Build(); => var dataSource = dataSourceBuilder.Build();) Note: I am using DB first approach. any help is really appreciated. Thanks
6 Replies
YazanSh
YazanShOP2y ago
Angius
Angius2y ago
I am using the DB First approach
My condolences That said, the scaffolding thingamajig should've created the enum for you I think
YazanSh
YazanShOP2y ago
Angius
Angius2y ago
¯\_(ツ)_/¯ then, never had to wrestle with db-first thankfully
YazanSh
YazanShOP2y ago
wasn't my choice 😦 My manager asked me to because DB was already built and there are still many changes on the tables the project is still being built from scratch
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server