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
[WIP] Timespan support #3994
base: master
Are you sure you want to change the base?
[WIP] Timespan support #3994
Conversation
d4b14e3
to
025ab02
Compare
@@ -501,7 +501,7 @@ private TransformInfo ConvertExpressionTransformer(Expression e) | |||
return new TransformInfo(ConvertExpression(expr)); | |||
} | |||
|
|||
if (ma.Member.DeclaringType == typeof(TimeSpan)) | |||
/*if (ma.Member.DeclaringType == typeof(TimeSpan)) |
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.
I'm not sure I'm comfortable with take 55 lines of code and simply commenting them out. If these lines are not needed, they should be removed entirely. The whole point of source control is that the lines are still available in history if they are needed for reverting.
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.
It's not yet finished. I will remove them if it is. I only need answers to my questions, the whole pull still needs work, and I will remove the commented out code.
I only now recoginzed, that a few others things break
&& Nullable.GetUnderlyingType(ex.Right.Type) == typeof(TimeSpan)) | ||
{ | ||
var method = MemberHelper.MethodOf( | ||
() => Sql.DateAdd(Sql.DateParts.Millisecond, 0, DateTime.MinValue)); |
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.
spacing is off here. this should only be one-tab to the right of var
, not six.
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.
I will look after the formating if everything works and is okay
@@ -1330,7 +1330,7 @@ public DefaultMappingSchema() : base(new DefaultMappingSchemaInfo()) | |||
AddScalarType(typeof(decimal), DataType.Decimal); | |||
AddScalarType(typeof(DateTime), DataType.DateTime2); | |||
AddScalarType(typeof(DateTimeOffset), DataType.DateTimeOffset); | |||
AddScalarType(typeof(TimeSpan), DataType.Time); | |||
AddScalarType(typeof(TimeSpan), DataType.Int64); |
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.
This is likely to break existing consumers. It should be done as a separate PR with support from the entire team, and it would not have my support.
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.
Don't know what will break. But clearly the Datatype "Time" wich is for a Time in Day is not the correct one
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.
You may not like it, but historically, TimeSpan
was used for the sql time
type, so it is accurate to the historical and technical reality.
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.
Yeah, for sure if we won't do this change, I can remove. But atm. I'll leave it. But whole calculation with timespans will not work with type, so everyone who will the correct functionality need than to apply a custom mapping.
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.
There are two sides to this coin.
If you think "what should TimeSpan
map to", then you're right time
is a very bad choice.
If you think "what should time
map to", then some people thought TimeSpan
was the most fitting type in early .net.
In modern .net time
would have a natural fit as TimeOnly
.
For TimeSpan
, SQL:2008 defines an INTERVAL
type that is supported by many RDBMS including Oracle, MySQL, Postgre, MariaDB, Ingres. As such this would be a better default mapping (that would be overriden by providers not supporting INTERVAL
, such as MSSQL).
In any case we need to be careful with backward compatibility. Isn't changing this default mapping is going to break existing consumers that have time
in their DB?
Now a little bit more info: At first, the pull request is not yet done, the code needs to be cleaned up (remove commented, fix spaceing, ...) The complexity results in, that the TimeSpan datatype has no coresponding type in most databases, so the Ticks will be used (100 nanoseconds) in a bigint field. But in postgres we have a interval type, wich is used for timespan. So if I calculate a datediff automaticaly it should also be a interval type, for this I added the "DatePart.Interval" to the datediff function. |
Source/LinqToDB/Sql/Sql.TimeSpan.cs
Outdated
var timeSpan = builder.GetExpression("timeSpan"); | ||
|
||
var dt = DataType.Undefined; | ||
if (timeSpan is SqlField f) |
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.
Is this the correct way to check for the type of the Field in the Database?
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.
use timeSpan.GetExpressionType()
helper
/azp run test-all |
I'd agree with @viceroypenguin here: historically, If everyone agreed that mapping Another possibility would be to add a deprecation notice (perhaps via included .NET analyzer) to inform users that the Another point of consideration is 'what is |
At the moment I've switched back to "time" cause some tests break. If we change it, for sure it this should be a major version change. But for now it's also okay for me if we leave it. |
Can we not put the change behind an option? That's what we usually do for this kind of breaking change. |
we could. atm, i'm looking that all unit tests work again. found some wich don't and then I'll look. |
And what is for example with the expressions in the expressions.cs, they are in a static field, so how should we make them optional? |
… already uses a mapping to interval type
3a8381e
to
26b42db
Compare
/azp run test-all |
Azure Pipelines successfully started running 1 pipeline(s). |
Test baselines changed by this PR. Don't forget to merge/close baselines PR after this pr merged/closed. |
/azp run test-all |
Azure Pipelines successfully started running 1 pipeline(s). |
Test baselines changed by this PR. Don't forget to merge/close baselines PR after this pr merged/closed. |
Fix #3993
Fix #4306
Fix #2950
Open Questions/Tasks