-
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
EF.Functions: Translating ISDATE to SQL Server #16471
Conversation
src/EFCore.SqlServer/Query/Pipeline/SqlServerMethodCallTranslatorProvider.cs
Show resolved
Hide resolved
8f4ec7a
to
871ce80
Compare
Can you tell me why my tests broke? I did not find anything, only messages CI. |
Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.IsDate[expression] is missing |
/// <param name="_">The DbFunctions instance.</param> | ||
/// <param name="expression">Expression to validate</param> | ||
/// <returns>true to valid and false not valid.</returns> | ||
public static bool IsDate( |
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.
@divega - Should this return bool or int. SqlServer ISDATE returns int
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.
Note: as I reported here: #16471 (comment).
It would be much nicer and semantic to use Boolean, since ISDATE returns only 0/1, but if we should follow exactly what SQLServer tells us, we should return an integer, but I would be happy if it was boolean already that makes more sense.
src/EFCore.SqlServer/Query/Pipeline/SqlServerIsDateFunctionTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Pipeline/SqlServerIsDateFunctionTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Pipeline/SqlServerIsDateFunctionTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Pipeline/SqlServerIsDateFunctionTranslator.cs
Outdated
Show resolved
Hide resolved
8304e54
to
8bb238d
Compare
src/EFCore.SqlServer/Query/Pipeline/SqlServerIsDateFunctionTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Pipeline/SqlServerIsDateFunctionTranslator.cs
Outdated
Show resolved
Hide resolved
Only waiting for @divega to decide on return type now. |
It appears that functions like ISDATE and ISNUMERIC only return int for historical reasons. All other things being equal, bool seems a better type for the method in .NET, unless there are drawbacks with it. |
@@ -556,6 +560,64 @@ public virtual void DateDiff_Nanosecond() | |||
} | |||
} | |||
|
|||
[ConditionalFact] |
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.
Can we also have a positive test which recognize and returns true. In projection & where both.
@@ -879,5 +879,17 @@ private static bool ContainsCore(string propertyName, string searchCondition, in | |||
=> (startTimeSpan.HasValue && endTimeSpan.HasValue) | |||
? (int?)DateDiffNanosecond(_, startTimeSpan.Value, endTimeSpan.Value) | |||
: null; | |||
|
|||
/// <summary> | |||
/// Validate if a date is valid.. |
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.
Validate if the given string is a valid date.
/// </summary> | ||
/// <param name="_">The DbFunctions instance.</param> | ||
/// <param name="expression">Expression to validate</param> | ||
/// <returns>true to valid and false not valid.</returns> |
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.
true for valid date and false otherwise.
Sql server's select priorTo1753=isDate('1000-01-01')
,highPrecision = isDate('2019-07-15T00:00:00.1234') For my money, a better test might be to use the |
c1bc361
to
857eaf7
Compare
@smitpatel I made the requested adjustments and also the rebase. |
@ralmsdeveloper - Thanks. |
Implementation for #8488
As this function returns 0/1.
So I thought it would be better to make it Boolean.
https://docs.microsoft.com/en-us/sql/t-sql/functions/isdate-transact-sql?view=sql-server-2017
cc/ @divega @smitpatel