Efcore: "Data type 'nvarchar' is not supported in this form" after scaffolding from database

Created on 21 Aug 2017  Â·  24Comments  Â·  Source: dotnet/efcore

I have used efcore and netcore since the betas without much trouble but now I am stuck. I had a fully functional application using 1.x. After upgrading to EFCore 2.0 I now get the error below. (also tried with preview 2.1.0-preview1-26723 same error)

I have tried to scaffold in a new project and get the same result. I dont't have any reference to datatype nvarchar except for nvarchar(max), every other column has a hasmaxlength only.

I guess the nvarchar(max) is somewhat of a problem here or any ideas??!? I have three databases I scaffold, all three are updated using the new tools.

"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."

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Further technical details

EF Core version: 2.1.0-preview1-26723
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10 build 16251
IDE: Visual Studio 15.3.1

closed-duplicate

All 24 comments

The exact same bug is present in 2.0.0.

An nvarchar(4000) gets scaffolded as this :

entity.Property(e => e.Name)
                    .HasColumnName("name")
                    .HasColumnType("nvarchar");

Which result in the above error.

nvarchar(MAX) correctly gets scaffolded to this :

entity.Property(e => e.Name).HasColumnName("name");

And other lengths like 255 correctly to this :

entity.Property(e => e.Name)
                    .HasColumnName("name")
                    .HasMaxLength(255);

However, this was apparently adressed in issue #9188 and fixed. Any chance to see it in 2.0.1 ?

What do you need to know more to look into this? I could pm the contextfile if that could help.

That is not how this gets scaffolded.

I have:

entity.Property(e => e.AppointmentDescription)
.IsRequired()
.HasColumnType("nvarchar(max)");

entity.Property(e => e.FormData)
.IsRequired()
.HasColumnType("nvarchar");

HasColumnType("nvarchar");
Duplicate of https://github.com/aspnet/EntityFrameworkCore/issues/9188 ? (Fixed in 2.1) - you can fix by hand....

@ErikEJ I am running 2.1.0-preview as you can see above. Do you know what build it will be included in?

It was only fixed 3 days ago, so it could be a single digit number of days from now

I cant find 2.1.0-preview of the All-package or EFcore
https://www.nuget.org/packages/Microsoft.AspNetCore.All/
https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/

Did something change? How am one to install previews from now on?

@bassebaba The preview (stable dev build) feed url is: https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json

Still not fixed... Even in the version 2.1 preview

@statler - Can you write the full version no. you used to verify?

Verified that this is fixed in version 2.1.0-preview1-26816

Duplicate of #9188

Getting this error :
An exception of type 'System.ArgumentException' occurred in Microsoft.EntityFrameworkCore.SqlServer.dll but was not handled in user code: '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.'

My scaffolded nvarchar fields :
// Created_IP nvarchar(50, null)
entity.Property(e => e.CreatedIp)
.HasColumnName("Created_IP")
.HasMaxLength(50)
// Modified_IP nvarchar(50, null)
entity.Property(e => e.ModifiedIp)
.HasColumnName("Modified_IP")
.HasMaxLength(50)

The scaffolding seems correct (as far as I read from your comments), but still it is throwing the error.
I am using ef core version 2.0.0.

@fatherofwhales It is only nvarchar(max) fields that are scaffolded in an insupported syntax.

Look for HasColumnType("nvarchar"). I need to replace all of those every time I scaffold with HasMaxLength(4000).

@johanskoldekrans Fixed. The error wasn't pointing to the entity that had this HasColumnType("nvarchar") property which got me confused. Thanks.

@fatherofwhales @johanskoldekrans - filed #9761 to improve error message. Thanks for feedback

Hi @fschlaef, @bassebaba, @statler, @fatherofwhales. We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:

  • Did you consider testing your code against the pre-release builds?
  • Was there anything blocking you from using pre-release builds?
  • What do you think could make it easier for you to use pre-release builds in the future?

Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward.

I have to host the web sites on IIS and since I couldn't get hold of the
updated server hosting for the previews I had to downgrade which is
extremely frustrating since just have fixed so many bugs since release. And
the strategy to not release those fixes as patches is something I just
can't understand.

On version 1.* when you had another documentation site you could choose the
dev-bransch and download the server hosting files. But it is still scary to
go live with preview versions for production systems.

So patch up, test and release would be something I would appreciate more.

ATB,

Johan

2017-09-12 20:09 GMT+02:00 Arthur Vickers notifications@github.com:

Hi @fschlaef https://github.com/fschlaef, @bassebaba
https://github.com/bassebaba, @statler https://github.com/statler,
@fatherofwhales https://github.com/fatherofwhales. We are gathering
information on the use of EF Core pre-release builds. You reported this
issue shortly after the release of 2.0.0 RTM. It would be really helpful if
you could let us know:

  • Did you consider testing your code against the pre-release builds?
  • Was there anything blocking you from using pre-release builds?
  • What do you think could make it easier for you to use pre-release
    builds in the future?

Thanks in advance for any feedback. Hopefully this will help us to
increase the value of pre-release builds going forward.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aspnet/EntityFrameworkCore/issues/9501#issuecomment-328935825,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AR1Ti6BAlGspDTc5Gob4dpEYnJ7h6qC4ks5shsi9gaJpZM4O9Q9u
.

--
Johan Sköldekrans
IT

Telefon +46 8 463 8000 <+4684638000>
Direkt +46 8 463 8029 <+4684638029>
Mobil +0760856512

Erik Penser Bank
Apelbergsgatan 27
Box 7405
103 91 Stockholm

--

www.penser.se
Disclaimer: www.penser.se/disclaimer

No, I've never considered pre-release builds. I just updated to 2.0.0 when I found there was no support for System.Transactions in 1.*. I would have used the pre-release builds but by the time I updated, 2.0.0 RTM was already there.

Maybe I'll use the pre-release builds in the future. Moreover, I just started with asp.net core.

Hi @fschlaef, @bassebaba, @statler, @fatherofwhales. We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:

Did you consider testing your code against the pre-release builds?
Was there anything blocking you from using pre-release builds?
What do you think could make it easier for you to use pre-release builds in the future?
Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward.

@ajcvickers
Short version: Too much work involved in testing a pre-release. My team does not have the time/resources to test the pre-release in parallel to the current release, and then migrate once RTM is available.
Sadly / childish / spoiled / call-it-whatever-you-want, we expect RTM to work 100% :P

As one programmer to another, I'm sad and ashamed to give you that explanation, but that's the reality I work with. My team barely gets enough "code out of the door" by upper management expectations, we don't even get resources to test our own code good enough.
At least now with .net core on Linux + Docker we have a continuous delivery chain so that we can patch our test-in-production-model fast ;)

@bassebaba @AmarDuplantier @johanskoldekrans Thanks for the feedback; much appreciated.

@johanskoldekrans Is this nuget package a pre-release build? What are all the features updated in it? I am looking for stored procedure support - ef dbcontext scaffold not generating functions for stored procedures from database. Is it there yet? Where can I find the release notes?

@AmarDuplantier EFCore is version 2.0 and part of the dotnetcore metapackage or as a separat package.

Everything is available on GitHub since it is open source so you can view the actual code or view outstanding issues or features being worked on right here.

https://github.com/aspnet/EntityFrameworkCore

In file DbContext search for "nvarchar" -> (this is bug) and change to 'nvarchar(16)'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vijayantkatyal picture vijayantkatyal  Â·  321Comments

abdu292 picture abdu292  Â·  99Comments

dragnilar picture dragnilar  Â·  236Comments

divega picture divega  Â·  146Comments

0xdeafcafe picture 0xdeafcafe  Â·  189Comments