mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-07 00:40:55 +08:00
@@ -301,6 +301,8 @@ FROM (
|
||||
GROUP BY a.""EntityId"", b.""StartDateTime"", b.""EndDateTime"" ) a", sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class IIFTest02Model1
|
||||
{
|
||||
public long _Id { get; set; }
|
||||
@@ -324,5 +326,51 @@ FROM (
|
||||
public DateTime EndDateTime { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void IIFTest03()
|
||||
{
|
||||
var parameters = new List<DbParameter>();
|
||||
|
||||
var fsql = g.dameng;
|
||||
var sql = "";
|
||||
var startTime = DateTime.UtcNow;
|
||||
//fsql.CodeFirst.SyncStructure<IIFTest03Model>();
|
||||
//fsql.Insert(new IIFTest03Model { StartDateTime = startTime, EndDateTime = startTime.AddHours(1) }).ExecuteAffrows();
|
||||
|
||||
var query = fsql.Select<IIFTest03Model>();
|
||||
|
||||
//sql = query.ToSql(model => new
|
||||
//{
|
||||
// Timespan = (model.EndDateTime - model.StartDateTime).TotalSeconds,
|
||||
//});
|
||||
|
||||
var result = query.ToList(model => new
|
||||
{
|
||||
Timespan = (model.EndDateTime - model.StartDateTime),
|
||||
});
|
||||
|
||||
// sql = query.ToSql();
|
||||
// Assert.Equal($@"SELECT *
|
||||
//FROM (
|
||||
// SELECT a.""EntityId"", b.""StartDateTime"" ""DateTime"", sum(((strftime('%s',case when a.""StopTime"" > b.""EndDateTime"" then b.""EndDateTime"" else a.""StopTime"" end)-strftime('%s',case when a.""StartTime"" < b.""StartDateTime"" then b.""StartDateTime"" else a.""StartTime"" end)))) ""TotalRunTime"", count(1) ""Count""
|
||||
// FROM ""IIFTest02Model1"" a
|
||||
// INNER JOIN ""IIFTest02Model2"" b ON b.""StartDateTime"" = '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}' AND a.""StartTime"" <= b.""EndDateTime"" AND a.""StopTime"" > b.""StartDateTime""
|
||||
// GROUP BY a.""EntityId"", b.""StartDateTime"", b.""EndDateTime"" ) a", sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 任务统计日期
|
||||
/// </summary>
|
||||
public class IIFTest03Model
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public DateTime StartDateTime { get; set; }
|
||||
public DateTime EndDateTime { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,11 +389,11 @@ namespace FreeSql.Dameng
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
switch (memberName)
|
||||
{
|
||||
case "TotalDays": return $"(cast({getExp(date1)} as timestamp with time zone)-{getExp(date2)})";
|
||||
case "TotalHours": return $"((cast({getExp(date1)} as timestamp with time zone)-{getExp(date2)})*24)";
|
||||
case "TotalMilliseconds": return $"((cast({getExp(date1)} as timestamp with time zone)-{getExp(date2)})*{24 * 60 * 60 * 1000})";
|
||||
case "TotalMinutes": return $"((cast({getExp(date1)} as timestamp with time zone)-{getExp(date2)})*{24 * 60})";
|
||||
case "TotalSeconds": return $"((cast({getExp(date1)} as timestamp with time zone)-{getExp(date2)})*{24 * 60 * 60})";
|
||||
case "TotalDays": return $"DATEDIFF(Day, {getExp(date2)}, {getExp(date1)})";
|
||||
case "TotalHours": return $"DATEDIFF(Hour, {getExp(date2)}, {getExp(date1)})";
|
||||
case "TotalMilliseconds": return $"DATEDIFF(MS, {getExp(date2)}, {getExp(date1)})";
|
||||
case "TotalMinutes": return $"DATEDIFF(Minute, {getExp(date2)}, {getExp(date1)})";
|
||||
case "TotalSeconds": return $"DATEDIFF(Second, {getExp(date2)}, {getExp(date1)})";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -435,7 +435,8 @@ namespace FreeSql.Dameng
|
||||
case "Subtract":
|
||||
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName)
|
||||
{
|
||||
case "System.DateTime": return $"((cast({left} as timestamp with time zone)-{args1})*{24 * 60 * 60})";
|
||||
//case "System.DateTime": return $"((cast({left} as timestamp with time zone)-{args1})*{24 * 60 * 60})";
|
||||
case "System.DateTime": return $"DATEDIFF(Second, {args1}, {left})";
|
||||
}
|
||||
break;
|
||||
case "Equals": return $"({left} = {args1})";
|
||||
|
||||
Reference in New Issue
Block a user