-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
RevEng: generated props .HasMaxLength(x).HasColumnType("varchar") create varchar(1) columns in DB #4312
Comments
Thanks for reporting this @umu24013. I'll look into it. |
Once we have |
Fix is checked in with #4348, commit 443c52b. Details: using both In addition to that for properties with type So I updated the scaffolding code to look again at any Lastly, since the big change to use |
@lajones just to make sure I understand, do we still generate properties of a specific CLR type and either |
@divega Depends what you mean. If the underlying store type is |
BTW @divega The fluent API tests and the annotations tests have the results for an |
Thanks for the links. I see that for something like a column I think once we have #3420 fixed it should be possible to just use |
@divega Agreed. See comment from @rowanmiller above. |
Got it. Thanks for clarifying. |
@divega No worries. BTW are we planning to provide a |
We could. As a general principle I would be conservative about adding new annotations on our own initiative and wait for customer feedback or PRs instead 😄 |
The dnx command with the -a option
dnx ef dbcontext scaffold <connection string> EntityFramework.MicrosoftSqlServer -a -c <context name> -o <output dir>
generates incomplete entity properties for the varchar data type in the OnModelCreating method:
for nvarchar(x) it generates .HasMaxLength(x)
but for varchar(x) it generates .HasMaxLength(x).HasColumnType("varchar")
where x is data length
Then, when I call Database.EnsureCreated() from the generated dbcontext, it creates varchar(1) columns in the DB rather then varchar(x).
As a result, the SQL Server throws en exception "String or binary data would be truncated" when trying to write to those castrated columns.

The text was updated successfully, but these errors were encountered: