Skip to content

Storing and retrieval of enum values not working. #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bitzblitz opened this issue Feb 9, 2025 · 5 comments
Closed

Storing and retrieval of enum values not working. #25

bitzblitz opened this issue Feb 9, 2025 · 5 comments

Comments

@bitzblitz
Copy link
Contributor

When the database saves an enum value it saves it as an integer. This is fine, but when retrieving the data it can't turn the integer back into an enum value.

@bitzblitz bitzblitz changed the title Storing nad retreival of enum values not working. Storing and retrieval of enum values not working. Feb 9, 2025
@magiccodingman
Copy link
Owner

Can you explain further? Same thing happens for example when I save to a normal database. An enum saves as an integer because it is an integer. When I read back that integer, I have to know to convert it back to an enum.

Just an example on C# scaffolded entity model of mine:

[NotMapped]
public Status StatusEnum
{
    get
    {
        Status enumstat = (Status)Enum.ToObject(typeof(Status), StatusDbint);
        return enumstat;
    }
    set
    {
        StatusDbint = (int)value;
    }
}

[Column("Status_DBInt")]
public int StatusDbint { get; set; }

This is my lazy man way of doing it lol, but the StatusDbint is the integer it saves to the database, as where I have my non mapped statusEnum that converts and sets that int properly.

Just showing this to see if we're on the same page, or maybe I'm misunderstanding, or maybe you've had different entity framework experiences that I'm not aware of :)

@magiccodingman
Copy link
Owner

Will re-open the issue if we discover this is an issue, but from my current understanding, this is by design.

@bitzblitz
Copy link
Contributor Author

It has been my experience that a all databases can read back what they wrote. The underlying implementation should not have any effect on the read/write process. This is encapsulation.

I agree that integers are a good choice for the underlying implementation. They can even handle [Flags] enum types.

Entity Framework handles enums as I have described.

@yueyinqiu
Copy link
Collaborator

#32

@magiccodingman
Copy link
Owner

@yueyinqiu We need to test this with the new serializer. I Haven't checked out your unit tests yet, but was just thinking about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants