Skip to content

Adding a TimeSpan to a DateTime, can it be done, and is it the right thing to do? #4106

Closed Answered by MaceWindu
BenjaBobs asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think we provide such operation out-of-box, but you can add own mapping to sql.

  1. You can define custom function
[Sql.Expression("your_custom_sql_here")]
public static DateTime MyAddFunction(DateTime date, TimeSpan interval) => throw new InvalidOperationException("server-side only method");
  1. Override binary operation mapping (but I would not recommend it as it will hide) using Expressions.MapBinary, but I would not recommend it as it will override old behavior and requires function from (1) anyways

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by MaceWindu
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants