Efcore.pg: EF Core generate enum scaffold error (2.1.0-preview2)

Created on 6 May 2018  路  3Comments  路  Source: npgsql/efcore.pg

0.Quick description

I'm getting an error when I use EF Core to generate a DBContext that contains an enum type

1.How to reproduce

1.1 Create an enum type

CREATE TYPE public."ProxyTypeEnum" AS ENUM ('HTTP', 'HTTPS', 'SOCKS5', 'SOCKS4');

1.2 Use EF Core to generate a DBContext

dotnet ef dbcontext scaffold "Server=YOURHOSTNAME;Database=YOURDB;Port=YOURPORT;UserId=YOURUSERID;Password=********;" Npgsql.EntityFrameworkCore.PostgreSQL

1.3 Display Error!

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The call is ambiguous between the following methods or properties:
'Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateLiteral(Microsoft.EntityFrameworkCore.Design.NestedClosureCodeFragment)' and 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateLiteral(System.Array)'
   at CallSite.Target(Closure , CallSite , CSharpUtilities , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.Generate(MethodCallCodeFragment methodCallCodeFragment)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.GenerateOnModelCreating(IModel model, Boolean useDataAnnotations)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.GenerateClass(IModel model, String contextName, String connectionString, Boolean useDataAnnotations, Boolean suppressConnectionStringWarning)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.WriteCode(IModel model, String namespace, String contextName, String connectionString, Boolean useDataAnnotations, Boolean suppressConnectionStringWarning)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.GenerateModel(IModel model, String namespace, String contextDir, String contextName, String connectionString, ModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String namespace, String language, String contextDir, String contextName, 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, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations,Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.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 call is ambiguous between the following methods or properties: 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateLiteral(Microsoft.EntityFrameworkCore.Design.NestedClosureCodeFragment)' and 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateLiteral(System.Array)'

2.Environment variables

dotnet core version: 2.1.300-preview2-008533
dotnet ef core version: 2.1.0-preview2-30571(bundled with dotnet core 2.1.300-preview2 sdk)
OS: win10-x64(10.0.16299)
PostgreSQL version: 10 (docker)

3.Tips

My English is not good.If you have questions to ask me please do not use English abbreviations

bug

All 3 comments

Can you please specify which version of the Npgsql EF Core provider you're using (Npgsql.EntityFrameworkCore.PostgreSQL)? If it's not 2.1.0-preview2 please try upgrading to that.

Sorry, I forgot to provide the version of the package.

I currently use 2.1.0-preview2

.csproj

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0-preview2-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0-preview2-final" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.0-preview2" />
  </ItemGroup>

There have been some EF Core changes recently around literal value generation in scaffolding. After updating to their latest CI packages and making the small change above, I can confirm that scaffolding enums works again.

Was this page helpful?
0 / 5 - 0 ratings