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

"Data type 'nvarchar' is not supported in this form" after scaffolding from database #9501

Closed
johanskoldekrans opened this issue Aug 21, 2017 · 24 comments

Comments

@johanskoldekrans
Copy link

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

@fschlaef
Copy link

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 ?

@johanskoldekrans
Copy link
Author

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

@johanskoldekrans
Copy link
Author

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");

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 21, 2017

HasColumnType("nvarchar");
Duplicate of #9188 ? (Fixed in 2.1) - you can fix by hand....

@johanskoldekrans
Copy link
Author

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

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 21, 2017

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

@bassebaba
Copy link

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?

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 22, 2017

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

@statler
Copy link

statler commented Aug 28, 2017

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

@smitpatel
Copy link
Contributor

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

@smitpatel
Copy link
Contributor

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

@smitpatel
Copy link
Contributor

Duplicate of #9188

@smitpatel smitpatel marked this as a duplicate of #9188 Aug 28, 2017
@AmarDuplantier
Copy link

AmarDuplantier commented Sep 11, 2017

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.

@johanskoldekrans
Copy link
Author

@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).

@AmarDuplantier
Copy link

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

@smitpatel
Copy link
Contributor

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

@ajcvickers
Copy link
Member

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.

@johanskoldekrans
Copy link
Author

johanskoldekrans commented Sep 13, 2017 via email

@AmarDuplantier
Copy link

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.

@bassebaba
Copy link

@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 ;)

@ajcvickers
Copy link
Member

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

@AmarDuplantier
Copy link

@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?

@johanskoldekrans
Copy link
Author

@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

@lqvinh2
Copy link

lqvinh2 commented Sep 26, 2017

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

@ajcvickers ajcvickers removed this from the 2.1.0 milestone Oct 6, 2017
@smitpatel smitpatel removed their assignment Jan 12, 2022
@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
Projects
None yet
Development

No branches or pull requests

9 participants