Skip to content
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

Migrations: Convert enum values to underlying type #4061

Closed
delautour opened this issue Dec 13, 2015 · 8 comments
Closed

Migrations: Convert enum values to underlying type #4061

delautour opened this issue Dec 13, 2015 · 8 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@delautour
Copy link

When creating a migration to add an enum column, the namespace of the enum is not included in the resulting migration.

EG:

  migrationBuilder.AddColumn<int>(
                name: "Status",
                table: "CommandRecord",
                nullable: false,
                defaultValue: CommandStatus.Pending);

This results in DNX,Version=v4.5.1 error CS0103: The name 'CommandStatus' does not exist in the current context when running dnx ef database update

@bricelam
Copy link
Contributor

This is a bug. We shouldn't be referencing the enum value at all here--it may change over time. Instead we should use the int literal.

@alexmurari
Copy link
Contributor

@bricelam
Actually it has to be a char, since an enum could have a char value.
Ex.:

    public enum MyEnum
    {
        MyEnumItem = 'A'
    }

@bricelam
Copy link
Contributor

To get technical, it will be the underlying type of the enum which, in .NET can be byte, sbyte, short, ushort, int, uint, long, or ulong. In your example, the character literal specified is implicitly converted to int--the underlying type of MyEnum--during compilation.

@bricelam
Copy link
Contributor

Marking for re-triage. #4353 perpetuates this issue into the model snapshot.

@bricelam bricelam removed this from the 7.0.0 milestone Jan 21, 2016
@bricelam bricelam changed the title Generated migration does not include enum namespace. Migrations: Convert enum values to underlying type Jan 25, 2016
@rowanmiller rowanmiller added this to the 1.0.0-rc2 milestone Feb 1, 2016
@rowanmiller rowanmiller assigned smitpatel and unassigned bricelam Feb 1, 2016
@rowanmiller
Copy link
Contributor

@smitpatel we had another issue where we decided to just convert default values to the underlying type (rather than storing as the enum value)... so that work should resolve this one too.

@smitpatel
Copy link
Contributor

The other issue (#4286) was not allowing user to set default value for enums. While fixing it, we removed serialization introduced (which was causing the types to be from a fixed list) and converted it to enum value. Since Migrations also have same issue that user-defined enum is used instead of underlying value (this issue), we decided to fix it in model snapshot together.

@rowanmiller
Copy link
Contributor

So does that mean this one was fixed as part of the other change?

@smitpatel
Copy link
Contributor

The other one is partially fixed. It allows users to set default values now but it introduce this issue in model snapshot. Since migrations is already facing this issue, model snapshot & migrations can both be fixed together.

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.0.0-rc2, 1.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

6 participants