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

Exception "Data type 'nvarchar' is not supported in this form..." during scaffolding #13609

Closed
olavivaino opened this issue Oct 12, 2018 · 2 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@olavivaino
Copy link

Doing dbontext scaffolding on command line for existing DB, throws exception System.ArgumentException. No context or other files are generated.
Command line: dotnet ef dbcontext scaffold "Data Source=sql_srv;Initial Catalog=sql_db;UserID=user;Password=*" Microsoft.EntityFrameworkCore.SqlServer -o Model

There are similar errors reported on #9814, #9188, #9501. However it seems those issues are about exception thrown when using scaffolded model. My case is different - exception is thrown when scaffolding db. No model files are generated, not even output directory "Model" is created.
Database does have columns with datatype nvarchar(max) and nvarchar(4000).

Exception message: System.ArgumentException: Data type 'nvarchar' is not supported in this form. Either specify the length explicitly in the type name, for example as 'nvarchar(16)', or remove the data type and use APIs such as HasMaxLength to allow EF choose the data type.
Stack trace: at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerTypeMapper.ValidateTypeName(String storeType)
   at Microsoft.EntityFrameworkCore.Storage.Internal.FallbackRelationalTypeMappingSource.FindMappingForStoreTypeName(RelationalTypeMappingInfo& mappingInfo)
   at Microsoft.EntityFrameworkCore.Storage.Internal.FallbackRelationalTypeMappingSource.FindMapping(RelationalTypeMappingInfo& mappingInfo)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.<FindMappingWithConversion>b__7_0(ValueTuple`3 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo& mappingInfo, IReadOnlyList`1 principals)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(String storeTypeName)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ScaffoldingTypeMapper.FindMapping(String storeType, Boolean keyOrIndex, Boolean rowVersion)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetTypeScaffoldingInfo(DatabaseColumn column)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitColumn(EntityTypeBuilder builder, DatabaseColumn column)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitColumns(EntityTypeBuilder builder, ICollection`1 columns)
   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, Boolean useDatabaseNames)
   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)

Steps to reproduce

  1. Have a sql db sql_db that does have columns with datatype nvarchar(max) and/or nvarchar(4000).
  2. Run on command line: dotnet ef dbcontext scaffold "Data Source=sql_srv;Initial Catalog=sql_db;UserID=user;Password=*" Microsoft.EntityFrameworkCore.SqlServer -o Model

### Further technical details
Entity Framework Core .NET Command-line Tools
2.1.0-preview1-28290 (Version="2.1.0-preview1-final" in .csproj)
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Mac OS
IDE: VS Code
@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 13, 2018

Looks like you are running a old beta version of EF Core

@olavivaino
Copy link
Author

Thanks for the hint!
Indeed, the issue was in the package Microsoft.EntityFrameworkCore.Tools that was not the latest version.
But it was so logical to suspect "Entity Framework Core .NET Command-line Tools" package that produced exception.

I got model scaffolded using following versions combination:




<DotNetCliToolReference
    Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
    Version="2.1.0-preview1-final" />

Hopefully this can help out someone else.

@ajcvickers ajcvickers added closed-no-further-action The issue is closed and no further action is planned. customer-reported labels Oct 14, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants