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

HasMaxLength(4000) set to NVARCHAR(MAX) #8685

Closed
stevanusw opened this issue Jun 2, 2017 · 11 comments
Closed

HasMaxLength(4000) set to NVARCHAR(MAX) #8685

stevanusw opened this issue Jun 2, 2017 · 11 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@stevanusw
Copy link

Steps to reproduce

I have the following API:
builder.Entity() .Property(p => p.Message).IsRequired().HasMaxLength(4000);

However, SQL Server uses NVARCHAR(MAX) instead of NVARCHAR(4000).

Further technical details

EF Core version: 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 1.1.2
Operating system: Windows 7
IDE: Visual Studio Community 2017

@stevanusw
Copy link
Author

Note that the Migration's Up() method correctly generate the following codes:
migrationBuilder.AddColumn(
name: "Message",
table: "EventLogs",
maxLength: 4000,
nullable: false);

@smitpatel
Copy link
Member

Can you explain what do you mean by this?

However, SQL Server uses NVARCHAR(MAX) instead of NVARCHAR(4000).

@stevanusw
Copy link
Author

What I meant is that the datatype is NVARCHAR(MAX) instead of NVARCHAR(4000).

@smitpatel
Copy link
Member

Can you also post output of Script-Migration (dotnet ef migration script if using dotnet cli)

@stevanusw
Copy link
Author

That's a good idea, let me take a look.

@stevanusw
Copy link
Author

  1. Fluent API
    8685_1

  2. Migration
    8685_2

  3. SQL
    8685_3

The above screenshots should describe the problem. Thanks.

@smitpatel
Copy link
Member

smitpatel commented Jun 2, 2017

https://docs.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql

nvarchar(4000) should be equivalent of nvarchar(max)
nvarchar(4001) should be equivalent of nvarchar(max). Error of 1.

@stevanusw
Copy link
Author

"Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000"
In SQL you can DECLARE @_string AS NVARCHAR(4000)
So, I don't think nvarchar(4000) should be equivalent of nvarchar(max) is correct.

@ajcvickers ajcvickers changed the title HasMaxLength(400) set to NVARCHAR(MAX) HasMaxLength(4000) set to NVARCHAR(MAX) Jun 2, 2017
@ajcvickers ajcvickers added this to the 2.0.0 milestone Jun 2, 2017
@ajcvickers
Copy link
Member

Off by one.

@ajcvickers ajcvickers assigned bricelam and unassigned bricelam Jun 2, 2017
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 20, 2017
@bricelam
Copy link
Contributor

This no longer repros on dev. Somebody must have inadvertently fixed it. 😉

@bricelam bricelam removed their assignment Jun 20, 2017
@smitpatel
Copy link
Member

ae2277e
Which removed the always setting size for parameters of string type. Instead null are now allowed which makes them nvarchar(max) again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

4 participants