mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 表达式 DateTime - DateTime 和 DateTime - TimeSpan 的解析支持;
This commit is contained in:
parent
5891493402
commit
4ade1c80b4
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ namespace FreeSql.Tests.DataContext.SqlServer
|
|||||||
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=(localdb)\\mssqllocaldb;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
|
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=(localdb)\\mssqllocaldb;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
|
.UseMonitorCommand(t => Trace.WriteLine(t.CommandText))
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
// ... initialize data in the test database ...
|
// ... initialize data in the test database ...
|
||||||
|
@ -493,6 +493,38 @@ namespace FreeSql.Tests.MySqlExpression {
|
|||||||
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
|
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract() {
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic111333` a
|
||||||
|
//WHERE (((timestampdiff(microsecond, now(), a.`CreateTime`)) / 1000000) > 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||||
|
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||||
|
//WHERE (((timestampdiff(microsecond, now(), a__Type.`Time`)) / 1000000) > 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||||
|
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||||
|
//WHERE (((timestampdiff(microsecond, now(), a__Type__Parent.`Time2`)) / 1000000) > 0);
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic111333` a
|
||||||
|
//WHERE (date_sub(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||||
|
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||||
|
//WHERE (date_sub(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||||
|
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||||
|
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
public void this_Equals() {
|
public void this_Equals() {
|
||||||
var data = new List<object>();
|
var data = new List<object>();
|
||||||
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||||
|
@ -466,31 +466,75 @@ namespace FreeSql.Tests.OracleExpression {
|
|||||||
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||||
//FROM `tb_topic111333` a
|
//FROM "TB_TOPIC111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a.`CreateTime`)) / 1000000) > 0);
|
//WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0)
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
//FROM "TB_TOPIC111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a__Type.`Time`)) / 1000000) > 0);
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
|
//WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0)
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
//FROM "TB_TOPIC111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a__Type__Parent.`Time2`)) / 1000000) > 0);
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
|
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||||
|
//WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0)
|
||||||
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||||
//FROM `tb_topic111333` a
|
//FROM "TB_TOPIC111333" a
|
||||||
//WHERE (date_sub(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
//WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//FROM "TB_TOPIC111333" a
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
//WHERE (date_sub(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
//WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//FROM "TB_TOPIC111333" a
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||||
|
//WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract() {
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||||
|
//FROM "TB_TOPIC111333" a
|
||||||
|
//WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0)
|
||||||
|
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
|
//FROM "TB_TOPIC111333" a
|
||||||
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
|
//WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0)
|
||||||
|
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
|
//FROM "TB_TOPIC111333" a
|
||||||
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
|
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||||
|
//WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0)
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||||
|
//FROM "TB_TOPIC111333" a
|
||||||
|
//WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
|
|
||||||
|
//FROM "TB_TOPIC111333" a
|
||||||
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
|
//WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||||
|
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||||
|
|
||||||
|
//FROM "TB_TOPIC111333" a
|
||||||
|
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||||
|
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||||
|
//WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void this_Equals() {
|
public void this_Equals() {
|
||||||
|
@ -466,31 +466,75 @@ namespace FreeSql.Tests.PostgreSQLExpression {
|
|||||||
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
//SELECT a."id", a."clicks", a."typeguid", a."title", a."createtime"
|
||||||
//FROM `tb_topic111333` a
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a.`CreateTime`)) / 1000000) > 0);
|
//WHERE ((((extract(epoch from (a."createtime")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 0)
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a__Type.`Time`)) / 1000000) > 0);
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//WHERE ((((extract(epoch from (a__Type."time")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 0)
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a__Type__Parent.`Time2`)) / 1000000) > 0);
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//LEFT JOIN "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||||
|
//WHERE ((((extract(epoch from (a__Type__Parent."time2")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 0)
|
||||||
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
//SELECT a."id", a."clicks", a."typeguid", a."title", a."createtime"
|
||||||
//FROM `tb_topic111333` a
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (date_sub(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
//WHERE (((a."createtime")::timestamp-((((1)*86400000000))||' microseconds')::interval) > a."createtime")
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (date_sub(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//WHERE (((a__Type."time")::timestamp-((((1)*86400000000))||' microseconds')::interval) > a."createtime")
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//LEFT JOIN "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||||
|
//WHERE (((a__Type__Parent."time2")::timestamp-((((1)*86400000000))||' microseconds')::interval) > a."createtime")
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract() {
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
//SELECT a."id", a."clicks", a."typeguid", a."title", a."createtime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//WHERE ((((extract(epoch from (a."createtime")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 0)
|
||||||
|
|
||||||
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//WHERE ((((extract(epoch from (a__Type."time")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 0)
|
||||||
|
|
||||||
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//LEFT JOIN "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||||
|
//WHERE ((((extract(epoch from (a__Type__Parent."time2")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 0)
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
//SELECT a."id", a."clicks", a."typeguid", a."title", a."createtime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//WHERE (((a."createtime")::timestamp-((((1)*86400000000))||' microseconds')::interval) > a."createtime")
|
||||||
|
|
||||||
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//WHERE (((a__Type."time")::timestamp-((((1)*86400000000))||' microseconds')::interval) > a."createtime")
|
||||||
|
|
||||||
|
//SELECT a."id", a."clicks", a."typeguid", a__Type."guid", a__Type."parentid", a__Type."name", a__Type."time", a."title", a."createtime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "testtypeinfo333" a__Type ON a__Type."guid" = a."typeguid"
|
||||||
|
//LEFT JOIN "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||||
|
//WHERE (((a__Type__Parent."time2")::timestamp-((((1)*86400000000))||' microseconds')::interval) > a."createtime")
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void this_Equals() {
|
public void this_Equals() {
|
||||||
|
@ -228,6 +228,17 @@ namespace FreeSql.Tests.SqlServerExpression {
|
|||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
|
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract() {
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
public void this_Equals() {
|
public void this_Equals() {
|
||||||
var data = new List<object>();
|
var data = new List<object>();
|
||||||
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||||
|
@ -466,31 +466,75 @@ namespace FreeSql.Tests.SqliteExpression {
|
|||||||
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
|
||||||
//FROM `tb_topic111333` a
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a.`CreateTime`)) / 1000000) > 0);
|
//WHERE (((strftime('%s',a."CreateTime")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a__Type.`Time`)) / 1000000) > 0);
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//WHERE (((strftime('%s',a__Type."Time")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (((timestampdiff(microsecond, now(), a__Type__Parent.`Time2`)) / 1000000) > 0);
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
|
||||||
|
//WHERE (((strftime('%s',a__Type__Parent."Time2")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
|
||||||
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
|
||||||
//FROM `tb_topic111333` a
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (date_sub(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
//WHERE (datetime(a."CreateTime",(-((1)*86400))||' seconds') > a."CreateTime")
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (date_sub(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//WHERE (datetime(a__Type."Time",(-((1)*86400))||' seconds') > a."CreateTime")
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
//FROM "tb_topic111333" a
|
||||||
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
|
||||||
|
//WHERE (datetime(a__Type__Parent."Time2",(-((1)*86400))||' seconds') > a."CreateTime")
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract() {
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||||
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//WHERE (((strftime('%s',a."CreateTime")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
|
||||||
|
|
||||||
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//WHERE (((strftime('%s',a__Type."Time")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
|
||||||
|
|
||||||
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
|
||||||
|
//WHERE (((strftime('%s',a__Type__Parent."Time2")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
|
||||||
|
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||||
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//WHERE (datetime(a."CreateTime",(-((1)*86400))||' seconds') > a."CreateTime")
|
||||||
|
|
||||||
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//WHERE (datetime(a__Type."Time",(-((1)*86400))||' seconds') > a."CreateTime")
|
||||||
|
|
||||||
|
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
|
||||||
|
//FROM "tb_topic111333" a
|
||||||
|
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
|
||||||
|
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
|
||||||
|
//WHERE (datetime(a__Type__Parent."Time2",(-((1)*86400))||' seconds') > a."CreateTime")
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void this_Equals() {
|
public void this_Equals() {
|
||||||
|
@ -332,6 +332,8 @@ namespace FreeSql.Internal {
|
|||||||
static ConcurrentDictionary<Type, MethodInfo> _dicExpressionLambdaToSqlAsSelectAnyMethodInfo = new ConcurrentDictionary<Type, MethodInfo>();
|
static ConcurrentDictionary<Type, MethodInfo> _dicExpressionLambdaToSqlAsSelectAnyMethodInfo = new ConcurrentDictionary<Type, MethodInfo>();
|
||||||
internal static ConcurrentDictionary<Type, PropertyInfo> _dicNullableValueProperty = new ConcurrentDictionary<Type, PropertyInfo>();
|
internal static ConcurrentDictionary<Type, PropertyInfo> _dicNullableValueProperty = new ConcurrentDictionary<Type, PropertyInfo>();
|
||||||
static ConcurrentDictionary<Type, Expression> _dicFreeSqlGlobalExtensionsAsSelectExpression = new ConcurrentDictionary<Type, Expression>();
|
static ConcurrentDictionary<Type, Expression> _dicFreeSqlGlobalExtensionsAsSelectExpression = new ConcurrentDictionary<Type, Expression>();
|
||||||
|
static MethodInfo MethodDateTimeSubtractDateTime = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(DateTime) });
|
||||||
|
static MethodInfo MethodDateTimeSubtractTimeSpan = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(TimeSpan) });
|
||||||
|
|
||||||
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc) {
|
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc) {
|
||||||
switch (oper) {
|
switch (oper) {
|
||||||
@ -342,6 +344,12 @@ namespace FreeSql.Internal {
|
|||||||
case "-":
|
case "-":
|
||||||
if (oper == "+" && (leftExp.Type == typeof(string) || rightExp.Type == typeof(string)))
|
if (oper == "+" && (leftExp.Type == typeof(string) || rightExp.Type == typeof(string)))
|
||||||
return _common.StringConcat(new[] { ExpressionLambdaToSql(leftExp, tsc), ExpressionLambdaToSql(rightExp, tsc) }, new[] { leftExp.Type, rightExp.Type });
|
return _common.StringConcat(new[] { ExpressionLambdaToSql(leftExp, tsc), ExpressionLambdaToSql(rightExp, tsc) }, new[] { leftExp.Type, rightExp.Type });
|
||||||
|
if (oper == "-" && leftExp.Type.NullableTypeOrThis() == typeof(DateTime)) {
|
||||||
|
if (rightExp.Type.NullableTypeOrThis() == typeof(DateTime))
|
||||||
|
return ExpressionLambdaToSql(Expression.Call(leftExp, MethodDateTimeSubtractDateTime, rightExp), tsc);
|
||||||
|
if (rightExp.Type.NullableTypeOrThis() == typeof(TimeSpan))
|
||||||
|
return ExpressionLambdaToSql(Expression.Call(leftExp, MethodDateTimeSubtractTimeSpan, rightExp), tsc);
|
||||||
|
}
|
||||||
return $"({ExpressionLambdaToSql(leftExp, tsc)} {oper} {ExpressionLambdaToSql(rightExp, tsc)})";
|
return $"({ExpressionLambdaToSql(leftExp, tsc)} {oper} {ExpressionLambdaToSql(rightExp, tsc)})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user