-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
ConfigureSmartEnum not working #554
Comments
can someone please help on this |
It looks right as is - if you create a minimal repo I can take a look. As a workaround you can try this: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<YourEntity>()
.Property(e => e.Unit)
.HasConversion(
v => v.Value, // Convert `SmartEnum` to its `value` (int)
v => UnitMaterial.FromValue(v) // Convert `value` (int) back to `SmartEnum`
);
} |
Hi @ardalis, thanks for the reply. yes, I did use this method to manual map the conversion for each SmartEnum. However, the document mentioned ConfigureSmartEnum is sufficient for configuring all SmartEnum. I tried many times, ends up I create a SmartEnumConverter myself.
and the
|
We are running into this same error when generating migrations since moving to .NET 9. Any entity that has changed since the previous migration and contains a smart enum generates this exception during the migration generation process, unless the workaround given by @ardalis is used in the entity configuration. I should note that this doesn't seem to effect runtime operation at all, it only seems to be required during the migration generation process if that helps troubleshooting at all. |
Yeah EF Core must have changed something in v9 I guess. We'll take a look and figure out how to do a more general solution (again) as soon as we can. Community assistance appreciated as always, including reproductions of the problem in clean repos so if we come up with a fix we can test it with your scenario. |
this is my ConfigureConventions
The smart enum
How I use it under entity
The exception 'No suitable constructor was found for entity type 'UnitMaterial'. The following constructors had parameters that could not be bound to properties of the entity type: Cannot bind 'name', 'value' in 'UnitMaterial(string name, int value)'
how can I fix this ? please help
UnitMaterial and Entity is under my DOMAIN project, and dbContext is under INFRASTRUCTURE project
My specs
.NET 8.0
SmartEnum 8.1
SmartEnum.EFCore 8.1
The text was updated successfully, but these errors were encountered: