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: Enum literal generated for defaultValue #6193

Closed
Bartmax opened this issue Jul 28, 2016 · 6 comments
Closed

Migrations: Enum literal generated for defaultValue #6193

Bartmax opened this issue Jul 28, 2016 · 6 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

@Bartmax
Copy link

Bartmax commented Jul 28, 2016

Add a migration when a model has an enum fails to include the using for the appropiate namespace on the migration file and results in compilation error.

migrationBuilder.AddColumn<int>(
                name: "EnumName",
                table: "TableWithEnum",
                nullable: false,
                defaultValue: EnumName.None);

adding the using by hand solves the issue.

@rowanmiller
Copy link
Contributor

Migrations actually shouldn't use the enum at all (since you may remove the enum from the model at some point in the future). It should use the underlying value (i.e. 0 in this case). I thought we had a dupe of this already, but I couldn't find it.

@rowanmiller
Copy link
Contributor

@Bartmax which versions of the packages are you using? We thought this was fixed in RTM (but maybe we missed a case)

@Bartmax
Copy link
Author

Bartmax commented Jul 29, 2016

@rowanmiller I'm using 1.0 (RTM). And yup, It happened that I removed a type and I was unable to work with migrations, so using the underlying type makes lot of sense.

Just in case, the enum is defined as:

[Flags]
public enum MyEnum
{
    None = 0,
    First = 1,
    Second = 2,
    Third = 4,
    ...
}

@smitpatel
Copy link
Contributor

smitpatel commented Jul 29, 2016

#4061 was older issue. Looks like we have regressed.

@rowanmiller
Copy link
Contributor

Thanks for the info - assigning to fix in 1.1

@bricelam
Copy link
Contributor

I found the root cause here. Don't worry, @smitpatel, it's not a regression.

Because a non-nullable column is being added, the model differ is synthesizing a default. However, it is not unwrapping the enum type before getting a default value.

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 31, 2016
@bricelam bricelam changed the title Migrations fails to adds corresponding using when using enums Migrations: Enum literal generated for defaultValue Aug 31, 2016
@bricelam bricelam removed the tools label Sep 8, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.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

5 participants