mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-20 07:10:56 +08:00
- 忧化 DateTime.Subtract(date).TotalDays 表达式解析对应 datediff(day, date1, date2);
This commit is contained in:
@@ -379,6 +379,18 @@ namespace FreeSql.Custom.MySql
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateDiff(string memberName, Expression date1, Expression date2, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
switch (memberName)
|
||||
{
|
||||
case "TotalDays": return $"timestampdiff(day,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalHours": return $"timestampdiff(hour,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalMinutes": return $"timestampdiff(minute,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalSeconds": return $"timestampdiff(second,{getExp(date2)},{getExp(date1)})";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
|
||||
@@ -384,6 +384,19 @@ namespace FreeSql.Custom.Oracle
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateDiff(string memberName, Expression date1, Expression date2, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
switch (memberName)
|
||||
{
|
||||
case "TotalDays": return $"(({getExp(date1)}+0)-({getExp(date2)}+0))";
|
||||
case "TotalHours": return $"((({getExp(date1)}+0)-({getExp(date2)}+0))*24)";
|
||||
case "TotalMilliseconds": return $"((({getExp(date1)}+0)-({getExp(date2)}+0))*{24 * 60 * 60 * 1000})";
|
||||
case "TotalMinutes": return $"((({getExp(date1)}+0)-({getExp(date2)}+0))*{24 * 60})";
|
||||
case "TotalSeconds": return $"((({getExp(date1)}+0)-({getExp(date2)}+0))*{24 * 60 * 60})";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
|
||||
@@ -381,6 +381,19 @@ namespace FreeSql.Custom.SqlServer
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateDiff(string memberName, Expression date1, Expression date2, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
switch (memberName)
|
||||
{
|
||||
case "TotalDays": return $"datediff(day,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalHours": return $"datediff(hour,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalMilliseconds": return $"datediff(millisecond,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalMinutes": return $"datediff(minute,{getExp(date2)},{getExp(date1)})";
|
||||
case "TotalSeconds": return $"datediff(second,{getExp(date2)},{getExp(date1)})";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
|
||||
Reference in New Issue
Block a user