admin管理员组文章数量:1023538
In Postgresql 16 I have a custom enum type schema.status
. I updated the npgsql package to the latest version and modified code that was broken due to the new way of mapping enums.
Entity Framework queries that used to work are getting translated with the cast that produces error.
var pendingOrderCheck = _data.Orders.GetFirstOrDefault(w => w.NonPublicSchoolId == schoolId && w.Status == Status.PENDING) == null ? false : true;
This gets translated to:
SELECT TOP(1)
o.id, o.bookbudgetcode, oments, o.nonpublicschoolid,
o.pogenerated, o.ponumber, o.shipbudgetcode, o.statuscode,
o.updatetime, o.updateuser, o.usedbookorder, o.usedok,
o.vendorid
FROM
textb_2025_149100900000.orders AS o
WHERE
(o.nonpublicschoolid == @__schoolId_0)
&& (**o.statuscode == 'PENDING'::"schema.status"**))
Which produces this error:
SqlState: 42704
MessageText: type "schema.status" does not exist
But the enum schema.status
does exist.
As directed mapped the enum now to:
services.AddDbContext<TBContext>(o => o.UseNpgsql(dbConnectionString, o => o.MapEnum<Status>("schema.status")));
In Postgresql 16 I have a custom enum type schema.status
. I updated the npgsql package to the latest version and modified code that was broken due to the new way of mapping enums.
Entity Framework queries that used to work are getting translated with the cast that produces error.
var pendingOrderCheck = _data.Orders.GetFirstOrDefault(w => w.NonPublicSchoolId == schoolId && w.Status == Status.PENDING) == null ? false : true;
This gets translated to:
SELECT TOP(1)
o.id, o.bookbudgetcode, oments, o.nonpublicschoolid,
o.pogenerated, o.ponumber, o.shipbudgetcode, o.statuscode,
o.updatetime, o.updateuser, o.usedbookorder, o.usedok,
o.vendorid
FROM
textb_2025_149100900000.orders AS o
WHERE
(o.nonpublicschoolid == @__schoolId_0)
&& (**o.statuscode == 'PENDING'::"schema.status"**))
Which produces this error:
SqlState: 42704
MessageText: type "schema.status" does not exist
But the enum schema.status
does exist.
As directed mapped the enum now to:
services.AddDbContext<TBContext>(o => o.UseNpgsql(dbConnectionString, o => o.MapEnum<Status>("schema.status")));
Share
Improve this question
edited Nov 19, 2024 at 4:48
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Nov 19, 2024 at 4:30
user22523049user22523049
32 bronze badges
1
- seems that EF adds " to the type name that causes the error as Postgres looks for the literal type "schema.status". The question is how to prevent it. – user22523049 Commented Nov 19, 2024 at 14:20
1 Answer
Reset to default 0You're passing schema.status
as a single string to MapEnum's name
parameter, which means that the enum really is supposed to be called schema.status
(as opposed to an enum named status
in the schema
schema. EFCore.PG is surrounding that name in double quotes, which is the correct thing to do.
If you want to map to an enum named status
in the schema schema
, you need to call the MapEnum overload that accepts the name and schema as separate parameters:
o.MapEnum<Status>("status", "schema")
In Postgresql 16 I have a custom enum type schema.status
. I updated the npgsql package to the latest version and modified code that was broken due to the new way of mapping enums.
Entity Framework queries that used to work are getting translated with the cast that produces error.
var pendingOrderCheck = _data.Orders.GetFirstOrDefault(w => w.NonPublicSchoolId == schoolId && w.Status == Status.PENDING) == null ? false : true;
This gets translated to:
SELECT TOP(1)
o.id, o.bookbudgetcode, oments, o.nonpublicschoolid,
o.pogenerated, o.ponumber, o.shipbudgetcode, o.statuscode,
o.updatetime, o.updateuser, o.usedbookorder, o.usedok,
o.vendorid
FROM
textb_2025_149100900000.orders AS o
WHERE
(o.nonpublicschoolid == @__schoolId_0)
&& (**o.statuscode == 'PENDING'::"schema.status"**))
Which produces this error:
SqlState: 42704
MessageText: type "schema.status" does not exist
But the enum schema.status
does exist.
As directed mapped the enum now to:
services.AddDbContext<TBContext>(o => o.UseNpgsql(dbConnectionString, o => o.MapEnum<Status>("schema.status")));
In Postgresql 16 I have a custom enum type schema.status
. I updated the npgsql package to the latest version and modified code that was broken due to the new way of mapping enums.
Entity Framework queries that used to work are getting translated with the cast that produces error.
var pendingOrderCheck = _data.Orders.GetFirstOrDefault(w => w.NonPublicSchoolId == schoolId && w.Status == Status.PENDING) == null ? false : true;
This gets translated to:
SELECT TOP(1)
o.id, o.bookbudgetcode, oments, o.nonpublicschoolid,
o.pogenerated, o.ponumber, o.shipbudgetcode, o.statuscode,
o.updatetime, o.updateuser, o.usedbookorder, o.usedok,
o.vendorid
FROM
textb_2025_149100900000.orders AS o
WHERE
(o.nonpublicschoolid == @__schoolId_0)
&& (**o.statuscode == 'PENDING'::"schema.status"**))
Which produces this error:
SqlState: 42704
MessageText: type "schema.status" does not exist
But the enum schema.status
does exist.
As directed mapped the enum now to:
services.AddDbContext<TBContext>(o => o.UseNpgsql(dbConnectionString, o => o.MapEnum<Status>("schema.status")));
Share
Improve this question
edited Nov 19, 2024 at 4:48
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Nov 19, 2024 at 4:30
user22523049user22523049
32 bronze badges
1
- seems that EF adds " to the type name that causes the error as Postgres looks for the literal type "schema.status". The question is how to prevent it. – user22523049 Commented Nov 19, 2024 at 14:20
1 Answer
Reset to default 0You're passing schema.status
as a single string to MapEnum's name
parameter, which means that the enum really is supposed to be called schema.status
(as opposed to an enum named status
in the schema
schema. EFCore.PG is surrounding that name in double quotes, which is the correct thing to do.
If you want to map to an enum named status
in the schema schema
, you need to call the MapEnum overload that accepts the name and schema as separate parameters:
o.MapEnum<Status>("status", "schema")
本文标签: Newest version of npgsql with Entity Framework casting enum type errorStack Overflow
版权声明:本文标题:Newest version of npgsql with Entity Framework casting enum type error - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745582212a2157374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论