question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for database enums

See original GitHub issue

PostgreSQL allows defining enums as first-class database types, which can then be used in regular columns. Npgsql exposes this by allowing users to define a mapping between a PostgreSQL enum and a CLR enum.

EF7’s type mapping now allows arbitrary types to be mapped to supported database types, this works very well with PostgreSQL types - types such as macaddr are successfully mapped in EF7 to .NET PhysicalAddress. However, when trying to add enum mapping support I ran into trouble - it seems that in various areas of the EF7 core enums are unwrapped and treated as their underlying numeric type instead (e.g. int).

I’m guessing this is to allow enums to be saved to numeric columns for databases which don’t support enums natively (e.g. SqlServer). Am I understanding the situation correctly, is database enum support currently impossible in EF7?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:16
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
ajcvickerscommented, Feb 6, 2018

@CoffeeDreamLabs I believe that the updates to the type mapper in 2.1 should allow the Postgres driver to support this starting in 2.1. /cc @roji

4reactions
rowanmillercommented, Mar 21, 2016

We will look at it again post v1.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which database systems support an ENUM data type ...
PostgreSQL supports ENUM from 8.3 onwards. For older versions, you can use : You can simulate an ENUM by doing something like this...
Read more >
Why would you store an enum in DB?
By keeping the enum in your database, and adding a foreign key on the table that contains an enum value you ensure that...
Read more >
Enum Support - Code First - EF6
This video and step-by-step walkthrough shows how to use enum types with Entity Framework Code First. It also demonstrates how to use enums...
Read more >
Documentation: 15: 8.7. Enumerated Types
Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in...
Read more >
Storing enum-style values in database - int vs. string?
My experience is that enum-style fields are pretty often stored as integers in the database. This means to keep things backward compatible ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found