-
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] Output the HasColumnType() and HasMaxLength() APIs correctly #4348
Conversation
@@ -18,6 +19,11 @@ public class SqlServerScaffoldingModelFactory : RelationalScaffoldingModelFactor | |||
{ | |||
private const int DefaultTimeTimePrecision = 7; | |||
|
|||
private static readonly ISet<string> _dataTypesForbiddingLength = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway we can capture this in the SqlServer type mapper? I thought it was already designed to handle lengths.
Seems like we could make improvements to reuse type mapping API. Perhaps we need new API, such as Thoughts on this @ajcvickers ? |
@natemcmaster @ajcvickers Nit: It would definitely have to be The problem is that different data types interpret having a null max length differently. For |
Or an overload.
To clarify, my point was that this logic could be placed in |
@natemcmaster Sort of. This is not just about type mapping. It would be perfectly legal for us to output e.g. So in the end we need 2 pieces of information out: 1) should we use I'll try to put all of that in |
7b34777
to
e4ddc3b
Compare
@ajcvickers Have updated as suggested above - could you give the final sign-off since Nate is away? |
Removing "Needs Review" while I rebase this on the renamed codebase and get it working again. Will put it back on when ready for review again. |
@@ -36,6 +38,11 @@ public class SqlServerTypeMapper : RelationalTypeMapper | |||
private readonly RelationalTypeMapping _decimal = new RelationalTypeMapping("decimal(18, 2)", typeof(decimal)); | |||
private readonly RelationalTypeMapping _time = new RelationalTypeMapping("time", typeof(TimeSpan)); | |||
|
|||
private static readonly ISet<string> _dataTypesForbiddingMaxLength = | |||
new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "image", "ntext", "text" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about rowversion and uniqueidentifier - would these map to byte[] and string CLR types, respectively, and need to be excluded?
Also, I don't think date, datetime, or smalldatetime allow max length (at least per SQL Server, not sure about HasMaxLength()
), but those would be excluded implicitly by CLR type in MaxLengthQualifiedDataType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't review just yet - I'm in the process of updating this and will add the "Needs Review" tag back when it's ready. Nonetheless I take your point and will check those scenarios.
expected by migrations and add tests.
e4ddc3b
to
443c52b
Compare
I tried to put the code in That said there are real synonyms for some types e.g. |
LGTM. |
Checked in with commit 443c52b. |
Note: opened issue #4425 to track trying to make the |
Fix for #4312.
For SQL Server this means for
nvarchar
columns (or synonyms) we useHasMaxLength()
and notHasColumnType()
, for other string types we useHasColumnType()
and notHasMaxLength()
. Similarly forvarbinary
(or synonyms) useHasMaxLength()
and notHasColumnType()
, but for other binary column types useHasColumnType()
and notHasMaxLength()
.