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

Sentinel not generated for enums on Optimize-DbContext #30832

Closed
rgordey opened this issue May 5, 2023 · 6 comments · Fixed by #30852
Closed

Sentinel not generated for enums on Optimize-DbContext #30832

rgordey opened this issue May 5, 2023 · 6 comments · Fixed by #30852
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@rgordey
Copy link

rgordey commented May 5, 2023

For about the last week, every release of EF Core Preview has had the same result...

public OrderStatus Status { get; set; }

public enum OrderStatus
{
    Entered = 1,
    PaymentReceived = 2,
    Shipped = 3
}

var status = runtimeEntityType.AddProperty(
                "Status",
                typeof(OrderStatus),
                propertyInfo: typeof(SalesOrder).GetProperty("Status", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
                fieldInfo: typeof(SalesOrder).GetField("<Status>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
                maxLength: 50,
                providerPropertyType: typeof(string),
                sentinel: ); <<== No entry
            status.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None);

Include provider and version information

EF Core version: 8.0.0-preview.5.23254.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.6

@ajcvickers ajcvickers self-assigned this May 9, 2023
@ajcvickers ajcvickers added this to the 8.0.0 milestone May 9, 2023
@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 May 9, 2023
@rgordey
Copy link
Author

rgordey commented May 15, 2023

I tested this last week and it was fixed. But the release today reintroduced/reverted the same problem.

@ajcvickers
Copy link
Contributor

@rgordey What do you mean by, "But the release today?" What version number?

@rgordey
Copy link
Author

rgordey commented May 15, 2023

@ajcvickers 8.0.0-preview.5.23265.4

@ajcvickers
Copy link
Contributor

@ajcvickers I'm not able to reproduce this. With that build, I see the following code generated:

var status = runtimeEntityType.AddProperty(
    "Status",
    typeof(OrderStatus),
    propertyInfo: typeof(Blog).GetProperty("Status", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
    fieldInfo: typeof(Blog).GetField("<Status>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
    sentinel: (OrderStatus)0);

Can you post a small, complete project with a model that reproduces what you are seeing?

@rgordey
Copy link
Author

rgordey commented May 16, 2023

@ajcvickers ,

I will spin up a sample today.

I suspect it has to do with one convention I am using to save enums as the string value.

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
        {
            configurationBuilder.Properties<Enum>()
                .HaveConversion<string>()
                .HaveMaxLength(50);

            configurationBuilder.Properties<string>()
                .HaveMaxLength(100);

            configurationBuilder.Properties<decimal>()
                .HavePrecision(18, 2);
        }

@rgordey
Copy link
Author

rgordey commented May 16, 2023

@ajcvickers,

I figured out my problem while trying to make a sample. I had the [Flags] attribute on the enum. But did not have a 0 value assigned.

@ajcvickers ajcvickers modified the milestones: 8.0.0, 8.0.0-preview4, 8.0.0-preview5 May 26, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-preview5, 8.0.0 Nov 14, 2023
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants