dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.69k stars 3.17k forks source link

System.ArgumentException: The string argument 'name' cannot be empty. #23509

Closed archanox closed 1 year ago

archanox commented 3 years ago

When scaffolding a 3rd party sqlite database (obtainable here https://veekun.com/static/pokedex/downloads/veekun-pokedex.sqlite.gz) I'm encountering the below issues. I thought it had something do with the quoted identifiers that use "Order" as a column name, but I was able to convert these to "Ordinal" in my local, but yielded the same issues. I don't know if this issue is isolated to Sqlite specifically, or EFCore as a whole.

PM> Scaffold-DbContext 'Data Source=C:\Temp\veekun-pokedex.sqlite' Microsoft.EntityFrameworkCore.Sqlite
Build started...
Build succeeded.
To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
System.ArgumentException: The string argument 'name' cannot be empty.
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder.HasIndex(String[] propertyNames, String name)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitUniqueConstraint(EntityTypeBuilder builder, DatabaseUniqueConstraint uniqueConstraint)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitUniqueConstraints(EntityTypeBuilder builder, ICollection`1 uniqueConstraints)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluarlize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The string argument 'name' cannot be empty.
PM>

Microsoft.Data.Sqlite version: 6.0.0-alpha.1.20417.8 (and 5.0.0) Microsoft.EntityFrameworkCore.Design version: 6.0.0-alpha.1.20417.8 Microsoft.EntityFrameworkCore.Sqlite version: 6.0.0-alpha.1.20417.8 Microsoft.EntityFrameworkCore.Tools version: 6.0.0-alpha.1.20417.8 Target framework:. .NET 5.0 Operating system: Windows 10 2004

ajcvickers commented 3 years ago

@archanox This looks like a duplicate of #23268, which will be released in 5.0.1 and is already in the 6.0 daily builds. However, it looks like you tested against an older daily build. Can you make sure you are using the "dotnet6" feed (https://github.com/dotnet/efcore/blob/main/docs/DailyBuilds.md#package-source-for-ef-core-60) and try again with the most recent build?

archanox commented 3 years ago

I've installed version 6.0.0-alpha.1.20601.1 and have run the same scaffolding PS command as above, and I am now getting;

Build started... Build succeeded. Missing required argument '\'.

archanox commented 3 years ago

Even when omitting the final parameter, and just calling Scaffold-DbContext 'Data Source=C:\Temp\veekun-pokedex.sqlite' then providing Microsoft.EntityFrameworkCore.Sqlite when prompted for a Provider yields the same result.

ajcvickers commented 3 years ago

@archanox Can you post the csproj file?

archanox commented 3 years ago
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
        <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-alpha.1.20580.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0-alpha.1.20580.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-alpha.1.20580.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

As you can see there, the version is one below the one I mentioned previously in the comment this morning. It still yields the same results. I haven't tried using the dotnet command outside of visual studio, and I haven't traversed all the versions until it is functional again. I'll report back here if I have any discoveries.

archanox commented 3 years ago
PS C:\temp\VeekunDatabase> dotnet tool update --global dotnet-ef --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json --version 6.0.0-alpha.1.20577.1
Tool 'dotnet-ef' was successfully updated from version '5.0.0' to version '6.0.0-alpha.1.20577.1'.
PS C:\temp\VeekunDatabase> dotnet ef dbcontext scaffold "Data Source=C:\temp\veekun-pokedex.sqlite" Microsoft.EntityFrameworkCore.Sqlite
Build started...
Build succeeded.
Missing required argument '<PROVIDER>'.
PS C:\temp\VeekunDatabase>

I was able to try this with the dotnet tool, but unfortunately, same issue...

ajcvickers commented 3 years ago

@archanox Unfortunately, I still can't reproduce this. I used the exact project file you posted and it didn't run into any issues.

@bricelam Any ideas here?

bricelam commented 3 years ago

Very strange...

ajcvickers commented 3 years ago

@archanox Can you post verbose output from running the command in the PMC?