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

Can't scaffold SQL Server index with fill factor in EF Core 6 preview 4 #25006

Closed
ErikEJ opened this issue May 31, 2021 · 1 comment · Fixed by #25008
Closed

Can't scaffold SQL Server index with fill factor in EF Core 6 preview 4 #25006

ErikEJ opened this issue May 31, 2021 · 1 comment · Fixed by #25008
Assignees
Labels
area-scaffolding area-sqlserver 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

@ErikEJ
Copy link
Contributor

ErikEJ commented May 31, 2021

System.Exception: Reverse engineer error: 
System.InvalidCastException: Unable to cast object of type 'System.Byte' to type 'System.Nullable`1[System.Int32]'.
   at int? Microsoft.EntityFrameworkCore.SqlServerIndexExtensions.GetFillFactor(IReadOnlyIndex index)
   at IEnumerable<IAnnotation> Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal.SqlServerAnnotationProvider.For(ITableIndex index)+MoveNext()
   at void Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(AnnotatableBase annotatable, IEnumerable<IAnnotation> annotations) x 2
   at IRelationalModel Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider)
   at IModel Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Add(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider)
   at void Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.InitializeModel(IModel model, bool preValidation)
   at IModel Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, bool designTime, IDiagnosticsLogger<Validation> validationLogger)+((ModelRuntimeInitializer, IModel model, bool designTime, IDiagnosticsLogger<Validation> validationLogger) args) => { } [0]
   at Annotation Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase+<>c__30<TValue, TArg>.<GetOrAddRuntimeAnnotationValue>b__30_0(?)+(string n, (Func<TArg, TValue> CreateValue, TArg Argument, AnnotatableBase Annotatable) t) => { }
   at TValue System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.GetOrAdd<TArg>(TKey key, Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument)
   at TValue Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.GetOrAddRuntimeAnnotationValue<TValue, TArg>(string name, Func<TArg, TValue> valueFactory, TArg factoryArgument)
   at IModel Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, bool designTime, IDiagnosticsLogger<Validation> validationLogger)
   at IModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options)
   at ScaffoldedModel RevEng.Core.ReverseEngineerScaffolder.ScaffoldModel(string connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions, bool removeNullableBoolDefaults, bool excludeNavigations, bool dbContextOnly, bool entitiesOnly, bool useSchemaFolders, ServiceProvider serviceProvider) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 212
   at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, ServiceProvider serviceProvider, List<string> schemas, string outputContextDir, string modelNamespace, string contextNamespace) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 58
   at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerRunner.cs:line 86
   at int efreveng.Program.Main(string[] args) in C:/Code/EFCorePowerTools/src/GUI/efreveng/Program.cs:line 58

    at  EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildResult (EFCorePowerTools, Version=2.5.665.0, Culture=neutral, PublicKeyToken=d9645e6262c2eca7)
    at  EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher+<GetOutputAsync>d__9.MoveNext (EFCorePowerTools, Version=2.5.665.0, Culture=neutral, PublicKeyToken=d9645e6262c2eca7)
    at  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher+<LaunchExternalRunnerAsync>d__5.MoveNext (EFCorePowerTools, Version=2.5.665.0, Culture=neutral, PublicKeyToken=d9645e6262c2eca7)
    at  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler+<GenerateFilesAsync>d__13.MoveNext (EFCorePowerTools, Version=2.5.665.0, Culture=neutral, PublicKeyToken=d9645e6262c2eca7)
    at  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  System.Runtime.CompilerServices.TaskAwaiter.GetResult (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    at  EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler+<ReverseEngineerCodeFirstAsync>d__6.MoveNext (EFCorePowerTools, Version=2.5.665.0, Culture=neutral, PublicKeyToken=d9645e6262c2eca7)

Include provider and version information

EF Core version: 6.0 preview 4
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: .NET 5.0

@roji roji self-assigned this Jun 1, 2021
@roji roji changed the title Potential bug in EF Core 6 preview 4 Can't scaffold SQL Server index with fill factor in EF Core 6 preview 4 Jun 1, 2021
@roji
Copy link
Member

roji commented Jun 1, 2021

This seems like a bug was was present in the original PR: the metadata APIs for index fill factor use int, but SqlServerDatabaseModelFactory produces a byte. However, before preview4 we didn't use the metadata APIs during scaffolding, so the issue didn't manifest.

(note also that in 5.0.6 we also scaffold .HasFillFactor((byte)80) with the useless cast because of this)

We could change the metadata APIs to accept a byte (which is what SQL Server's sys.indexes exposes), but at this point it's probably simpler (and less breaking) to just have SqlServerDatabaseModelFactory produce an int. We already have metadata validation in place that the value is between 0 and 100.

roji added a commit that referenced this issue Jun 1, 2021
@ajcvickers ajcvickers added this to the 6.0.0 milestone Jun 1, 2021
roji added a commit that referenced this issue Jun 2, 2021
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 2, 2021
@AndriySvyryd AndriySvyryd modified the milestones: 6.0.0, 6.0.0-preview6 Jul 2, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview6, 6.0.0 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-scaffolding area-sqlserver 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.

4 participants