Open flier268 opened 7 months ago
It seems that after scaffolding your database, you're changing the type of the CustomDate1Flag property - which should have been scaffolded as a simple int based on the database schema - to an enum type (EDateIsPrintFlag); at that point the default value scaffolded becomes incompatible.
@ajcvickers maybe we can make our default value compatibility check smarter, to allow an int value for an enum type backed by int... @flier268 in the meantime, you can manually change from the new HasDefaultValue(1)
to the previous HasDefaultValueSql("1")
- that should work.
@roji I created a t4 template to change the type to enum
There are a lot of Entity, so I don't want to manually edit.
@flier268 You should update your T4 template to handle the default value appropriately.
@ajcvickers I don't know how to modify T4 to use HasDefaultValueSql instead of HasDefaultValue, can you give me a little help?
Just know how to remove HasDefaultValue
var propertyFluentApiCalls = property.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations)
&& !(c.Method == "IsRequired" && Options.UseNullableReferenceTypes && !property.ClrType.IsValueType)
&& !c.Method.StartsWith("HasDefaultValue")); // Add this
I had a table [Plu]
I have the following C# code:
I am using the Entity Framework Core to scaffold my database context. The command I use is:
With EF Core version 8.0.0, the generated code is:
However, this results in an error:
EF Core version: 8.0.0
Previously, with an older version of EF Core, the generated code was: (7.0.14)
But this approach no longer works after upgrading to version 8.0.0. Can you help me correct this?
EF Core version: 8.0.0 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 8 Operating system: Win11 IDE: Visual Studio 2022 17.8.2