mysql/sqlserver CodeFirst 完成测试

This commit is contained in:
28810 2018-12-22 18:13:25 +08:00
parent 7a61aea544
commit 0ff422eeb6
26 changed files with 712 additions and 1067 deletions

View File

@ -1,7 +1,8 @@
# 表达式函数 # 表达式函数
| 表达式 | MySql | SqlServer | PostgreSQL | 功能说明 | | 表达式 | MySql | SqlServer | PostgreSQL | 功能说明 |
| - | - | - | - | - | | - | - | - | - | - |
| (a ?? b) | ifnull(a, b) | isnull(a, b) | coalesce(a, b) | 当a为null时取b值 | | a ? b : c | case when a then b else c end | case when a then b else c end | - | a成立时取b值否则取c值 |
| a ?? b | ifnull(a, b) | isnull(a, b) | coalesce(a, b) | 当a为null时取b值 |
| 数字 + 数字 | a + b | a + b | a + b | 数字相加 | | 数字 + 数字 | a + b | a + b | a + b | 数字相加 |
| 数字 + 字符串 | concat(a, b) | cast(a as varchar) + cast(b as varchar) | case(a as varchar) \|\| b | 字符串相加a或b任意一个为字符串时 | | 数字 + 字符串 | concat(a, b) | cast(a as varchar) + cast(b as varchar) | case(a as varchar) \|\| b | 字符串相加a或b任意一个为字符串时 |
| a - b | a - b | a - b | a - b | 减 | a - b | a - b | a - b | a - b | 减
@ -63,8 +64,8 @@
| a.Month | month(a) | datepart(month, a) | - | 月 | | a.Month | month(a) | datepart(month, a) | - | 月 |
| a.Second | second(a) | datepart(second, a) | - | 秒 | | a.Second | second(a) | datepart(second, a) | - | 秒 |
| a.Subtract(b) | timestampdiff(microsecond, b, a) | datediff(millisecond, b, a) * 1000 | - | 将a的值和b相减 | | a.Subtract(b) | timestampdiff(microsecond, b, a) | datediff(millisecond, b, a) * 1000 | - | 将a的值和b相减 |
| a.Ticks | timestampdiff(microsecond, '1970-1-1', a) * 10 + 621355968000000000 | datediff(millisecond, '1970-1-1', a) * 10000 + 621355968000000000 | - | 刻度总数 | | a.Ticks | timestampdiff(microsecond, '0001-1-1', a) * 10 | datediff(millisecond, '1970-1-1', a) * 10000 + 621355968000000000 | - | 刻度总数 |
| a.TimeOfDay | timestampdiff(microsecond, date_format(a, '1970-1-1 %H:%i:%s.%f'), a) + 62135596800000000 | '1970-1-1 ' + convert(varchar, a, 14) | - | 获取a的时间部分 | | a.TimeOfDay | timestampdiff(microsecond, date_format(a, '%Y-%m-%d'), a) | '1970-1-1 ' + convert(varchar, a, 14) | - | 获取a的时间部分 |
| a.Year | year(a) | datepart(year, a) | - | 年 | | a.Year | year(a) | datepart(year, a) | - | 年 |
| a.Equals(b) | a = b | a = b | - | 比较a和b相等 | | a.Equals(b) | a = b | a = b | - | 比较a和b相等 |
| a.CompareTo(b) | a - b | a - b | - | 比较a和b大小 | | a.CompareTo(b) | a - b | a - b | - | 比较a和b大小 |
@ -122,3 +123,22 @@
| Math.Sqrt(a) | sqrt(a) | sqrt(a) | - | - | | Math.Sqrt(a) | sqrt(a) | sqrt(a) | - | - |
| Math.Tan(a) | tan(a) | tan(a) | - | - | | Math.Tan(a) | tan(a) | tan(a) | - | - |
| Math.Truncate(a) | truncate(a, 0) | floor(a) | - | - | | Math.Truncate(a) | truncate(a, 0) | floor(a) | - | - |
### 类型转换
| 表达式 | MySql | SqlServer | PostgreSQL | 功能说明 |
| - | - | - | - | - |
| Convert.ToBoolean(a) | (a not in ('0','false)) | - | - | - |
| Convert.ToByte | cast(a as unsigned) | - | - | - |
| Convert.ToChar | substr(cast(a as char),1,1) | - | - | - |
| Convert.ToDateTime | cast(a as datetime) | - | - | - |
| Convert.ToDecimal | cast(a as decimal(36,18)) | - | - | - |
| Convert.ToDouble | cast(a as decimal(32,16)) | - | - | - |
| Convert.ToInt16 | cast(a as signed) | - | - | - |
| Convert.ToInt32 | cast(a as signed) | - | - | - |
| Convert.ToInt64 | cast(a as signed) | - | - | - |
| Convert.ToSByte | cast(a as signed) | - | - | - |
| Convert.ToSingle | cast(a as char) | - | - | - |
| Convert.ToString | cast(a as decimal(14,7)) | - | - | - |
| Convert.ToUInt16 | cast(a as unsigned) | - | - | - |
| Convert.ToUInt32 | cast(a as unsigned) | - | - | - |
| Convert.ToUInt64 | cast(a as unsigned) | - | - | - |

View File

@ -34,6 +34,83 @@ namespace FreeSql.Tests.MySql {
[Fact] [Fact]
public void ToList() { public void ToList() {
var t1 = g.mysql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
var t2 = g.mysql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
var sql1 = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).ToSql();
var sql2 = select.LeftJoin<TestTypeInfo>((a, b) => a.TestTypeInfoGuid == b.Guid && b.Name == "111").ToSql();
var sql3 = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid").ToSql();
//g.mysql.Select<TestInfo, TestTypeInfo, TestTypeParentInfo>().Join((a, b, c) => new Model.JoinResult3(
// Model.JoinType.LeftJoin, a.TypeGuid == b.Guid,
// Model.JoinType.InnerJoin, c.Id == b.ParentId && c.Name == "xxx")
//);
//var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((a, b, c) => new SelectFrom()
// .InnerJoin(a.TypeGuid == b.Guid)
// .LeftJoin(c.Id == b.ParentId)
// .Where(b.Name == "xxx"))
//.Where(a => a.Id == 1).ToSql();
var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.InnerJoin(a => a.TestTypeInfoGuid == b.Guid)
.LeftJoin(a => c.Id == b.ParentId)
.Where(a => b.Name == "xxx")).ToSql();
//.Where(a => a.Id == 1).ToSql();
var list111 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.InnerJoin(a => a.TestTypeInfoGuid == b.Guid)
.LeftJoin(a => c.Id == b.ParentId)
.Where(a => b.Name != "xxx"));
var list111sql = list111.ToSql();
var list111data = list111.ToList((a, b, c) => new {
a.Id,
title_substring = a.Title.Substring(0, 1),
a.Type,
ccc = new { a.Id, a.Title },
tp = a.Type,
tp2 = new {
a.Id,
tp2 = a.Type.Name
},
tp3 = new {
a.Id,
tp33 = new {
a.Id
}
}
});
var ttt122 = g.mysql.Select<TestTypeParentInfo>().Where(a => a.Id > 0).ToSql();
var sql5 = g.mysql.Select<TestInfo>().From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s).Where((a, b, c) => a.Id == b.ParentId).ToSql();
var t11112 = g.mysql.Select<TestInfo>().ToList(a => new {
a.Id,
a.Title,
a.Type,
ccc = new { a.Id, a.Title },
tp = a.Type,
tp2 = new {
a.Id,
tp2 = a.Type.Name
},
tp3 = new {
a.Id,
tp33 = new {
a.Id
}
}
});
var t100 = g.mysql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).Caching(50).ToList();
var t101 = g.mysql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).Caching(50).ToList();
var t1111 = g.mysql.Select<TestInfo>().ToList(a => new { a.Id, a.Title, a.Type });
var t2222 = g.mysql.Select<TestInfo>().ToList(a => new { a.Id, a.Title, a.Type.Name });
} }
[Fact] [Fact]
public void ToOne() { public void ToOne() {

View File

@ -7,6 +7,24 @@ using Xunit;
namespace FreeSql.Tests.MySql { namespace FreeSql.Tests.MySql {
public class MySqlCodeFirstTest { public class MySqlCodeFirstTest {
[Fact]
public void AddField() {
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
var id = g.mysql.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
}
public class TopicAddField {
[Column(IsIdentity = true)]
public int? Id { get; set; }
public int name { get; set; }
[Column(DbType = "varchar(200) not null", OldName = "title")]
public string title222 { get; set; } = "10";
}
[Fact] [Fact]
public void GetComparisonDDLStatements() { public void GetComparisonDDLStatements() {

View File

@ -0,0 +1,114 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MySqlExpression {
public class ConvertTest {
ISelect<Topic> select => g.mysql.Select<Topic>();
[Table(Name = "tb_topic")]
class Topic {
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int Clicks { get; set; }
public int TestTypeInfoGuid { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
class TestTypeInfo {
public int Guid { get; set; }
public int ParentId { get; set; }
public TestTypeParentInfo Parent { get; set; }
public string Name { get; set; }
}
class TestTypeParentInfo {
public int Id { get; set; }
public string Name { get; set; }
public List<TestTypeInfo> Types { get; set; }
}
[Fact]
public void ToBoolean() {
var data = new List<object>();
data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 2) > 0).ToList());
//SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime`
//FROM `tb_topic` a
//WHERE ((a.`Clicks` not in ('0','false')))
}
[Fact]
public void ToByte() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToByte(a.Clicks) > 0).ToList());
}
[Fact]
public void ToChar() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToBoolean(a.Clicks)).ToList());
}
[Fact]
public void ToDateTime() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
}
[Fact]
public void ToDecimal() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList());
}
[Fact]
public void ToDouble() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
}
[Fact]
public void ToInt16() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
}
[Fact]
public void ToInt32() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
}
[Fact]
public void ToInt64() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
}
[Fact]
public void ToSByte() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToSByte(a.Clicks) > 0).ToList());
}
[Fact]
public void ToSingle() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
}
[Fact]
public void this_ToString() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
}
[Fact]
public void ToUInt16() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
}
[Fact]
public void ToUInt32() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
}
[Fact]
public void ToUInt64() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
}
}
}

View File

@ -7,6 +7,30 @@ using Xunit;
namespace FreeSql.Tests.SqlServer { namespace FreeSql.Tests.SqlServer {
public class SqlServerCodeFirstTest { public class SqlServerCodeFirstTest {
[Fact]
public void AddField() {
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
var id = g.sqlserver.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
}
public class TopicAddField {
[Column(IsIdentity = true)]
public int Id { get; set; }
public int name { get; set; } = 3000;
[Column(DbType = "varchar(200) not null", OldName = "title")]
public string title222 { get; set; } = "333";
[Column(DbType = "varchar(200) not null")]
public string title222333 { get; set; } = "xxx";
[Column(DbType = "varchar(100) not null", OldName = "title122333aaa")]
public string titleaaa { get; set; } = "fsdf";
}
[Fact] [Fact]
public void GetComparisonDDLStatements() { public void GetComparisonDDLStatements() {

View File

@ -0,0 +1,111 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.SqlServerExpression {
public class ConvertTest {
ISelect<Topic> select => g.mysql.Select<Topic>();
[Table(Name = "tb_topic")]
class Topic {
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int Clicks { get; set; }
public int TestTypeInfoGuid { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
class TestTypeInfo {
public int Guid { get; set; }
public int ParentId { get; set; }
public TestTypeParentInfo Parent { get; set; }
public string Name { get; set; }
}
class TestTypeParentInfo {
public int Id { get; set; }
public string Name { get; set; }
public List<TestTypeInfo> Types { get; set; }
}
[Fact]
public void ToBoolean() {
var data = new List<object>();
data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 2) > 0).ToList());
}
[Fact]
public void ToByte() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToByte(a.Clicks) > 0).ToList());
}
[Fact]
public void ToChar() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToBoolean(a.Clicks)).ToList());
}
[Fact]
public void ToDateTime() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
}
[Fact]
public void ToDecimal() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList());
}
[Fact]
public void ToDouble() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
}
[Fact]
public void ToInt16() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
}
[Fact]
public void ToInt32() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
}
[Fact]
public void ToInt64() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
}
[Fact]
public void ToSByte() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToSByte(a.Clicks) > 0).ToList());
}
[Fact]
public void ToSingle() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
}
[Fact]
public void this_ToString() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
}
[Fact]
public void ToUInt16() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
}
[Fact]
public void ToUInt32() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
}
[Fact]
public void ToUInt64() {
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
}
}
}

View File

@ -39,33 +39,21 @@ namespace FreeSql.Tests.SqlServerExpression {
public void Now() { public void Now() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList()); data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime))
} }
[Fact] [Fact]
public void UtcNow() { public void UtcNow() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList()); data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(utc_timestamp(), '%Y-%m-%d') as datetime))
} }
[Fact] [Fact]
public void MinValue() { public void MinValue() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList()); data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('0001/1/1 0:00:00' as datetime), '%Y-%m-%d') as datetime))
} }
[Fact] [Fact]
public void MaxValue() { public void MaxValue() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList()); data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('9999/12/31 23:59:59' as datetime), '%Y-%m-%d') as datetime))
} }
[Fact] [Fact]
public void Date() { public void Date() {
@ -73,31 +61,10 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList()); data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList()); data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime));
data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList()); data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList());
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList()); data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList());
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList()); data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (((timestampdiff(microsecond, cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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, cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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, cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0)
} }
[Fact] [Fact]
public void TimeOfDay() { public void TimeOfDay() {
@ -105,17 +72,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList());
data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList()); data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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, date_format(a__Type.`Time`, '1970-1-1 %H:%i:%s.%f'), a__Type.`Time`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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, date_format(a__Type__Parent.`Time2`, '1970-1-1 %H:%i:%s.%f'), a__Type__Parent.`Time2`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000))
} }
[Fact] [Fact]
public void DayOfWeek() { public void DayOfWeek() {
@ -123,17 +79,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((dayofweek(a.`CreateTime`) - 1) > (dayofweek(now()) - 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 ((dayofweek(a__Type.`Time`) - 1) > (dayofweek(now()) - 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 ((dayofweek(a__Type__Parent.`Time2`) - 1) > (dayofweek(now()) - 1))
} }
[Fact] [Fact]
public void Day() { public void Day() {
@ -141,17 +86,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList()); data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList());
data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList()); data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (dayofmonth(a.`CreateTime`) > dayofmonth(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (dayofmonth(a__Type.`Time`) > dayofmonth(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (dayofmonth(a__Type__Parent.`Time2`) > dayofmonth(now()))
} }
[Fact] [Fact]
public void DayOfYear() { public void DayOfYear() {
@ -159,17 +93,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList()); data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList());
data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList()); data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (dayofyear(a.`CreateTime`) > dayofyear(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (dayofyear(a__Type.`Time`) > dayofyear(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (dayofyear(a__Type__Parent.`Time2`) > dayofyear(now()))
} }
[Fact] [Fact]
public void Month() { public void Month() {
@ -177,17 +100,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList()); data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList());
data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList()); data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (month(a.`CreateTime`) > month(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (month(a__Type.`Time`) > month(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (month(a__Type__Parent.`Time2`) > month(now()))
} }
[Fact] [Fact]
public void Year() { public void Year() {
@ -195,17 +107,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList()); data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList());
data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList()); data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (year(a.`CreateTime`) > year(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (year(a__Type.`Time`) > year(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (year(a__Type__Parent.`Time2`) > year(now()))
} }
[Fact] [Fact]
public void Hour() { public void Hour() {
@ -213,17 +114,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList()); data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList());
data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList()); data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (hour(a.`CreateTime`) > hour(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (hour(a__Type.`Time`) > hour(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (hour(a__Type__Parent.`Time2`) > hour(now()))
} }
[Fact] [Fact]
public void Minute() { public void Minute() {
@ -231,17 +121,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList()); data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList());
data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList()); data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (minute(a.`CreateTime`) > minute(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (minute(a__Type.`Time`) > minute(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (minute(a__Type__Parent.`Time2`) > minute(now()))
} }
[Fact] [Fact]
public void Second() { public void Second() {
@ -249,17 +128,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList()); data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList());
data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList()); data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (second(a.`CreateTime`) > second(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (second(a__Type.`Time`) > second(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (second(a__Type__Parent.`Time2`) > second(now()))
} }
[Fact] [Fact]
public void Millisecond() { public void Millisecond() {
@ -267,17 +135,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList()); data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList());
data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList()); data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (floor(microsecond(a.`CreateTime`) / 1000) > floor(microsecond(now()) / 1000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (floor(microsecond(a__Type.`Time`) / 1000) > floor(microsecond(now()) / 1000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (floor(microsecond(a__Type__Parent.`Time2`) / 1000) > floor(microsecond(now()) / 1000))
} }
[Fact] [Fact]
public void Ticks() { public void Ticks() {
@ -285,17 +142,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList()); data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList());
data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList()); data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((timestampdiff(microsecond, '1970-1-1', a.`CreateTime`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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, '1970-1-1', a__Type.`Time`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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, '1970-1-1', a__Type__Parent.`Time2`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000))
} }
[Fact] [Fact]
public void Add() { public void Add() {
@ -303,17 +149,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > now())
} }
[Fact] [Fact]
public void AddDays() { public void AddDays() {
@ -321,17 +156,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) day) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) day) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) day) > now())
} }
[Fact] [Fact]
public void AddHours() { public void AddHours() {
@ -339,17 +163,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) hour) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) hour) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) hour) > now())
} }
[Fact] [Fact]
public void AddMilliseconds() { public void AddMilliseconds() {
@ -357,17 +170,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) * 1000 microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) * 1000 microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) * 1000 microsecond) > now())
} }
[Fact] [Fact]
public void AddMinutes() { public void AddMinutes() {
@ -375,17 +177,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) minute) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) minute) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) minute) > now())
} }
[Fact] [Fact]
public void AddMonths() { public void AddMonths() {
@ -393,17 +184,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) month) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) month) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) month) > now())
} }
[Fact] [Fact]
public void AddSeconds() { public void AddSeconds() {
@ -411,17 +191,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) second) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) second) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) second) > now())
} }
[Fact] [Fact]
public void AddTicks() { public void AddTicks() {
@ -429,17 +198,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) / 10 microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) / 10 microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) / 10 microsecond) > now())
} }
[Fact] [Fact]
public void AddYears() { public void AddYears() {
@ -447,17 +205,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (date_add(a.`CreateTime`, interval (1) year) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) year) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) year) > now())
} }
[Fact] [Fact]
public void Subtract() { public void Subtract() {
@ -465,31 +212,10 @@ namespace FreeSql.Tests.SqlServerExpression {
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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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] [Fact]
public void this_Equals() { public void this_Equals() {
@ -497,17 +223,6 @@ namespace FreeSql.Tests.SqlServerExpression {
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());
data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList()); data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_add(a.`CreateTime`, interval (1) year) = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) year) = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
} }
[Fact] [Fact]
public void this_ToString() { public void this_ToString() {
@ -515,17 +230,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList()); data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList()); data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
} }
[Fact] [Fact]
@ -534,17 +238,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList()); data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList()); data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList()); data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (((a.`CreateTime`) - (now())) = 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) year)) - (now())) = 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) year)) - (now())) = 0)
} }
[Fact] [Fact]
public void DateTime_DaysInMonth() { public void DateTime_DaysInMonth() {
@ -552,17 +245,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList()); data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList());
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList()); data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList());
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList()); data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (dayofmonth(last_day(concat(year(a.`CreateTime`), month(a.`CreateTime`), '-01'))) > 30);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (dayofmonth(last_day(concat(year(a__Type.`Time`), month(a__Type.`Time`), '-01'))) > 30);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (dayofmonth(last_day(concat(year(a__Type__Parent.`Time2`), month(a__Type__Parent.`Time2`), '-01'))) > 30)
} }
[Fact] [Fact]
public void DateTime_Equals() { public void DateTime_Equals() {
@ -570,17 +252,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList()); data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList());
data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList()); data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList());
data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList()); data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_add(a.`CreateTime`, interval (1) year) = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type.`Time`, interval (1) year) = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
} }
[Fact] [Fact]
public void DateTime_IsLeapYear() { public void DateTime_IsLeapYear() {
@ -588,17 +259,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList()); data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList());
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList()); data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList());
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList()); data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (((year(a.`CreateTime`)) % 4 = 0 AND (year(a.`CreateTime`)) % 100 <> 0 OR (year(a.`CreateTime`)) % 400 = 0));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (((year(date_add(a__Type.`Time`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type.`Time`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type.`Time`, interval (1) year))) % 400 = 0));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (((year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 400 = 0))
} }
[Fact] [Fact]
public void DateTime_Parse() { public void DateTime_Parse() {
@ -606,17 +266,6 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList()); data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList());
data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList()); data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList());
data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList()); data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') as datetime) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (cast(date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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 (cast(date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now())
} }
} }
} }

View File

@ -36,9 +36,6 @@ namespace FreeSql.Tests.SqlServerExpression {
public void Empty() { public void Empty() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql()); data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (ifnull(a.`Title`, '') = '')
} }
[Fact] [Fact]
@ -48,40 +45,11 @@ namespace FreeSql.Tests.SqlServerExpression {
list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList()); list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList());
list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList()); list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList());
list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList()); list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE '%aaa')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE concat('%', a.`Title`))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE concat('%', concat(a.`Title`, 1)))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`))
list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList()); list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList());
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList());
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList());
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1)))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`))
} }
[Fact] [Fact]
public void EndsWith() { public void EndsWith() {
@ -90,40 +58,11 @@ namespace FreeSql.Tests.SqlServerExpression {
list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList()); list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList());
list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList()); list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList());
list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList()); list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE 'aaa%')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE concat(a.`Title`, '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE concat(concat(a.`Title`, 1), '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE((a.`Title`) LIKE concat(a__Type.`Name`, '%'))
list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList()); list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList());
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList());
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList());
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE 'aaa%')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a.`Title`, '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(concat(a.`Title`, 1), '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a__Type.`Name`, '%'))
} }
[Fact] [Fact]
public void Contains() { public void Contains() {
@ -132,40 +71,11 @@ namespace FreeSql.Tests.SqlServerExpression {
list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList()); list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList());
list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList()); list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList());
list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList()); list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE '%aaa%')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE concat('%', a.`Title`, '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE concat('%', a.`Title` +1, '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`, '%'))
list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList()); list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList());
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList());
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList());
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList()); list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa%')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`, '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1), '%'))
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`, '%'))
} }
[Fact] [Fact]
public void ToLower() { public void ToLower() {
@ -174,40 +84,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList()); data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList());
data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(a.`Title`) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(a.`Title`) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE(lower(a.`Title`) = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList()); data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList());
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList()); data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList());
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a__Type.`Name`)
} }
[Fact] [Fact]
public void ToUpper() { public void ToUpper() {
@ -216,40 +97,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList()); data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList());
data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(a.`Title`) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(a.`Title`) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (upper(a.`Title`) = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList()); data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList());
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList()); data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList());
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a__Type.`Name`)
} }
[Fact] [Fact]
public void Substring() { public void Substring() {
@ -258,40 +110,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList()); data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList());
data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (substr(a.`Title`, 1) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (substr(a.`Title`, 1) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (substr(a.`Title`, 1) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (substr(a.`Title`, 1) = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList()); data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList());
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList()); data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList());
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), char_length(a.`Title`) + 1) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, char_length(a.`Title`)) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, 3) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 2, 2) = a__Type.`Name`)
} }
[Fact] [Fact]
public void Length() { public void Length() {
@ -300,40 +123,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.Length == 1).ToList()); data.Add(select.Where(a => a.Title.Length == 1).ToList());
data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList()); data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList());
data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList()); data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (char_length(a.`Title`) = 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (char_length(a.`Title`) = 1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (char_length(a.`Title`) = char_length(a.`Title`) + 1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (char_length(a.`Title`) = char_length(a__Type.`Name`));
data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList()); data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList());
data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList()); data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList());
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList()); data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList());
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList()); data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a.`Title`) + 1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a__Type.`Name`))
} }
[Fact] [Fact]
public void IndexOf() { public void IndexOf() {
@ -342,40 +136,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList()); data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList());
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList()); data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList()); data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((locate(a.`Title`, 'aaa') - 1) = -1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = -1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1);
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList()); data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList());
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList()); data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList());
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList()); data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList()); data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa') - 1) = -1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = -1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1)
} }
[Fact] [Fact]
public void PadLeft() { public void PadLeft() {
@ -384,40 +149,11 @@ namespace FreeSql.Tests.SqlServerExpression {
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList()); //data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList());
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList()); //data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList());
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList()); //data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
////FROM `tb_topic` a, `TestTypeInfo` a__Type
////WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`);
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList()); //data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList());
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList()); //data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList());
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList()); //data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList());
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList()); //data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
////FROM `tb_topic` a, `TestTypeInfo` a__Type
////WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
} }
[Fact] [Fact]
public void PadRight() { public void PadRight() {
@ -426,40 +162,11 @@ namespace FreeSql.Tests.SqlServerExpression {
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList()); //data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList());
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList()); //data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList());
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList()); //data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
////FROM `tb_topic` a, `TestTypeInfo` a__Type
////WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`);
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList()); //data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList());
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList()); //data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList());
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList()); //data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList());
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList()); //data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
////FROM `tb_topic` a, `TestTypeInfo` a__Type
////WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
} }
[Fact] [Fact]
public void Trim() { public void Trim() {
@ -468,40 +175,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList()); data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList());
data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim('a' from a.`Title`) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim('b' from trim('a' from a.`Title`)) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (trim('c' from trim('b' from trim('a' from a.`Title`))) = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList()); data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList());
data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList()); data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList());
data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(concat(trim(a.`Title`), 'aaa')) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim('a' from concat(trim('a' from a.`Title`), 'aaa')) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim('b' from trim('a' from concat(trim('b' from trim('a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (trim('c' from trim('b' from trim('a' from concat(trim('c' from trim('b' from trim('a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
} }
[Fact] [Fact]
public void TrimStart() { public void TrimStart() {
@ -510,40 +188,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList()); data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList());
data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (ltrim(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'a' from trim(leading 'a' from a.`Title`)) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))) = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList()); data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList());
data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList()); data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList());
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (ltrim(concat(ltrim(a.`Title`), 'aaa')) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'a' from trim(leading 'a' from a.`Title`)), 'aaa'))) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))), 'aaa'))))) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))), 'aaa'))))))) = a__Type.`Name`)
} }
[Fact] [Fact]
public void TrimEnd() { public void TrimEnd() {
@ -552,40 +201,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList()); data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList());
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (rtrim(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'a' from a.`Title`) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'b' from trim(trailing 'a' from a.`Title`)) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))) = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList()); data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList());
data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList()); data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList());
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (rtrim(concat(rtrim(a.`Title`), 'aaa')) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'a' from concat(trim(trailing 'a' from a.`Title`), 'aaa')) = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'b' from trim(trailing 'a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
} }
[Fact] [Fact]
public void Replace() { public void Replace() {
@ -594,40 +214,11 @@ namespace FreeSql.Tests.SqlServerExpression {
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList()); data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList());
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList()); data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList());
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList()); data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (replace(a.`Title`, 'a', 'b') = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (replace(replace(a.`Title`, 'a', 'b'), 'b', 'c') = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a') = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a') = a__Type.`Name`);
data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList()); data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList());
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList()); data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList());
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList()); data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (concat(replace(a.`Title`, 'a', 'b'), 'aaa') = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (concat(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'aaa') = a.`Title`);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a'), 'aaa') = concat(a.`Title`, 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
//FROM `tb_topic` a, `TestTypeInfo` a__Type
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a'), 'aaa') = a__Type.`Name`)
} }
[Fact] [Fact]
public void CompareTo() { public void CompareTo() {
@ -636,40 +227,11 @@ namespace FreeSql.Tests.SqlServerExpression {
//data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList()); //data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList());
//data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList()); //data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList());
//data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList()); //data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (strcmp(a.`Title`, a.`Title`) = 0);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (strcmp(a.`Title`, a.`Title`) > 0);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (strcmp(a.`Title`, concat(a.`Title`, 1)) = 0);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
////FROM `tb_topic` a, `TestTypeInfo` a__Type
////WHERE (strcmp(a.`Title`, concat(a.`Title`, a__Type.`Name`)) = 0);
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList()); //data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList());
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList()); //data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList());
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList()); //data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList());
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList()); //data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (strcmp(concat(a.`Title`, 'aaa'), 'aaa') = 0);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (strcmp(concat(a.`Title`, 'aaa'), a.`Title`) > 0);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
////FROM `tb_topic` a
////WHERE (strcmp(concat(a.`Title`, 'aaa'), concat(a.`Title`, 1)) = 0);
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
////FROM `tb_topic` a, `TestTypeInfo` a__Type
////WHERE (strcmp(concat(a.`Title`, 'aaa'), a__Type.`Name`) = 0)
} }
} }
} }

View File

@ -35,226 +35,142 @@ namespace FreeSql.Tests.SqlServerExpression {
public void Zero() { public void Zero() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > 0)
} }
[Fact] [Fact]
public void MinValue() { public void MinValue() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > -922337203685477580)
} }
[Fact] [Fact]
public void MaxValue() { public void MaxValue() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) < 922337203685477580)
} }
[Fact] [Fact]
public void Days() { public void Days() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 86400000000) = 0)
} }
[Fact] [Fact]
public void Hours() { public void Hours() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 3600000000) mod 24 > 0)
} }
[Fact] [Fact]
public void Milliseconds() { public void Milliseconds() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000 mod 1000) > 0)
} }
[Fact] [Fact]
public void Minutes() { public void Minutes() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 60000000 mod 60) > 0)
} }
[Fact] [Fact]
public void Seconds() { public void Seconds() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000000 mod 60) > 0)
} }
[Fact] [Fact]
public void Ticks() { public void Ticks() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) * 10) > 0)
} }
[Fact] [Fact]
public void TotalDays() { public void TotalDays() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 86400000000) > 0)
} }
[Fact] [Fact]
public void TotalHours() { public void TotalHours() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 3600000000) > 0)
} }
[Fact] [Fact]
public void TotalMilliseconds() { public void TotalMilliseconds() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000) > 0)
} }
[Fact] [Fact]
public void TotalMinutes() { public void TotalMinutes() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 60000000) > 0)
} }
[Fact] [Fact]
public void TotalSeconds() { public void TotalSeconds() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000000) > 0)
} }
[Fact] [Fact]
public void Add() { public void Add() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) + (1 * 86400000000)) > 0)
} }
[Fact] [Fact]
public void Subtract() { public void Subtract() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) - (1 * 86400000000)) > 0)
} }
[Fact] [Fact]
public void CompareTo() { public void CompareTo() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0)
} }
[Fact] [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.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
} }
[Fact] [Fact]
public void this_ToString() { public void this_ToString() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList()); data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') = 'ssss')
} }
[Fact] [Fact]
public void TimeSpan_Compare() { public void TimeSpan_Compare() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList()); data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0)
} }
[Fact] [Fact]
public void TimeSpan_Equals() { public void TimeSpan_Equals() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
} }
[Fact] [Fact]
public void TimeSpan_FromDays() { public void TimeSpan_FromDays() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
} }
[Fact] [Fact]
public void TimeSpan_FromHours() { public void TimeSpan_FromHours() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 3600000000)))
} }
[Fact] [Fact]
public void TimeSpan_FromMilliseconds() { public void TimeSpan_FromMilliseconds() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000)))
} }
[Fact] [Fact]
public void TimeSpan_FromMinutes() { public void TimeSpan_FromMinutes() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 60000000)))
} }
[Fact] [Fact]
public void TimeSpan_FromSeconds() { public void TimeSpan_FromSeconds() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000000)))
} }
[Fact] [Fact]
public void TimeSpan_FromTicks() { public void TimeSpan_FromTicks() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList()); data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 / 10)))
} }
[Fact] [Fact]
public void TimeSpan_Parse() { public void TimeSpan_Parse() {
var data = new List<object>(); var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList()); data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (cast(date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') as signed) > 0)
} }
} }
} }

View File

@ -33,7 +33,7 @@ namespace FreeSql.Tests {
var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.InnerJoin(a => a.TypeGuid == b.Guid) .InnerJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => c.Id == b.ParentId) .LeftJoin(a => c.Id == b.ParentId)
.Where(a => b.Name == "xxx")); .Where(a => b.Name == "xxx")).ToSql();
//.Where(a => a.Id == 1).ToSql(); //.Where(a => a.Id == 1).ToSql();

View File

@ -28,5 +28,10 @@ namespace FreeSql.DataAnnotations {
/// 是否可DBNull /// 是否可DBNull
/// </summary> /// </summary>
public bool IsNullable { get; set; } public bool IsNullable { get; set; }
/// <summary>
/// 数据库默认值
/// </summary>
internal object DbDefautValue { get; set; }
} }
} }

View File

@ -17,21 +17,31 @@ namespace FreeSql.Internal {
switch (exp.NodeType) { switch (exp.NodeType) {
case ExpressionType.Quote: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand); case ExpressionType.Quote: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand);
case ExpressionType.Lambda: return ReadAnonymousField(_tables, field, parent, ref index, (exp as LambdaExpression)?.Body); case ExpressionType.Lambda: return ReadAnonymousField(_tables, field, parent, ref index, (exp as LambdaExpression)?.Body);
case ExpressionType.Negate:
case ExpressionType.NegateChecked:
field.Append(", ").Append(ExpressionLambdaToSql(exp, _tables, null, SelectTableInfoType.From, true)).Append(" as").Append(++index);
return false;
case ExpressionType.Convert: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand); case ExpressionType.Convert: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand);
case ExpressionType.Constant: case ExpressionType.Constant:
var constExp = exp as ConstantExpression; var constExp = exp as ConstantExpression;
field.Append(", ").Append(constExp?.Value).Append(" as").Append(++index); field.Append(", ").Append(constExp?.Value).Append(" as").Append(++index);
return false; return false;
case ExpressionType.Call:
field.Append(", ").Append(ExpressionLambdaToSql(exp, _tables, null, SelectTableInfoType.From, true)).Append(" as").Append(++index);
return false;
case ExpressionType.MemberAccess: case ExpressionType.MemberAccess:
var map = new List<SelectColumnInfo>(); if (_common.GetTableByEntity(exp.Type) != null) { //加载表所有字段
ExpressionSelectColumn_MemberAccess(_tables, map, SelectTableInfoType.From, exp, true); var map = new List<SelectColumnInfo>();
if (map.Count > 1) { ExpressionSelectColumn_MemberAccess(_tables, map, SelectTableInfoType.From, exp, true);
parent.Consturctor = map.First().Table.Table.Type.GetConstructor(new Type[0]); parent.Consturctor = map.First().Table.Table.Type.GetConstructor(new Type[0]);
parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties; parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties;
} for (var idx = 0; idx < map.Count; idx++) {
for (var idx = 0; idx < map.Count; idx++) { field.Append(", ").Append(map[idx].Table.Alias).Append(".").Append(_common.QuoteSqlName(map[idx].Column.Attribute.Name)).Append(" as").Append(++index);
field.Append(", ").Append(map[idx].Table.Alias).Append(".").Append(_common.QuoteSqlName(map[idx].Column.Attribute.Name)).Append(" as").Append(++index); parent.Childs.Add(new ReadAnonymousTypeInfo { CsName = map[idx].Column.CsName });
if (map.Count > 1) parent.Childs.Add(new ReadAnonymousTypeInfo { CsName = map[idx].Column.CsName }); }
} else {
field.Append(", ").Append(ExpressionLambdaToSql(exp, _tables, null, SelectTableInfoType.From, true)).Append(" as").Append(++index);
return false;
} }
return false; return false;
case ExpressionType.New: case ExpressionType.New:
@ -39,7 +49,7 @@ namespace FreeSql.Internal {
parent.Consturctor = newExp.Type.GetConstructors()[0]; parent.Consturctor = newExp.Type.GetConstructors()[0];
parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Arguments; parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Arguments;
for (var a = 0; a < newExp.Members.Count; a++) { for (var a = 0; a < newExp.Members.Count; a++) {
var child = new ReadAnonymousTypeInfo { CsName = newExp.Members[a].Name }; var child = new ReadAnonymousTypeInfo { CsName = newExp.Members[a].Name, CsType = newExp.Arguments[a].Type };
parent.Childs.Add(child); parent.Childs.Add(child);
ReadAnonymousField(_tables, field, child, ref index, newExp.Arguments[a]); ReadAnonymousField(_tables, field, child, ref index, newExp.Arguments[a]);
} }
@ -53,7 +63,7 @@ namespace FreeSql.Internal {
case ReadAnonymousTypeInfoConsturctorType.Arguments: case ReadAnonymousTypeInfoConsturctorType.Arguments:
var args = new object[parent.Childs.Count]; var args = new object[parent.Childs.Count];
for (var a = 0; a < parent.Childs.Count; a++) { for (var a = 0; a < parent.Childs.Count; a++) {
args[a] = ReadAnonymous(parent.Childs[a], dr, ref index); args[a] = Utils.GetDataReaderValue(parent.Childs[a].CsType, ReadAnonymous(parent.Childs[a], dr, ref index));
} }
return parent.Consturctor.Invoke(args); return parent.Consturctor.Invoke(args);
case ReadAnonymousTypeInfoConsturctorType.Properties: case ReadAnonymousTypeInfoConsturctorType.Properties:
@ -162,6 +172,9 @@ namespace FreeSql.Internal {
case ExpressionType.Negate: case ExpressionType.Negate:
case ExpressionType.NegateChecked: return "-" + ExpressionLambdaToSql((exp as UnaryExpression)?.Operand, _tables, _selectColumnMap, tbtype, isQuoteName); case ExpressionType.NegateChecked: return "-" + ExpressionLambdaToSql((exp as UnaryExpression)?.Operand, _tables, _selectColumnMap, tbtype, isQuoteName);
case ExpressionType.Constant: return _common.FormatSql("{0}", (exp as ConstantExpression)?.Value); case ExpressionType.Constant: return _common.FormatSql("{0}", (exp as ConstantExpression)?.Value);
case ExpressionType.Conditional:
var condExp = exp as ConditionalExpression;
return $"case when {ExpressionLambdaToSql(condExp.Test, _tables, _selectColumnMap, tbtype, isQuoteName)} then {ExpressionLambdaToSql(condExp.IfTrue, _tables, _selectColumnMap, tbtype, isQuoteName)} else {ExpressionLambdaToSql(condExp.IfFalse, _tables, _selectColumnMap, tbtype, isQuoteName)} end";
case ExpressionType.Call: case ExpressionType.Call:
var exp3 = exp as MethodCallExpression; var exp3 = exp as MethodCallExpression;
switch (exp3.Object?.Type.FullName ?? exp3.Method.DeclaringType.FullName) { switch (exp3.Object?.Type.FullName ?? exp3.Method.DeclaringType.FullName) {
@ -169,6 +182,7 @@ namespace FreeSql.Internal {
case "System.Math": return ExpressionLambdaToSqlCallMath(exp3, _tables, _selectColumnMap, tbtype, isQuoteName); case "System.Math": return ExpressionLambdaToSqlCallMath(exp3, _tables, _selectColumnMap, tbtype, isQuoteName);
case "System.DateTime": return ExpressionLambdaToSqlCallDateTime(exp3, _tables, _selectColumnMap, tbtype, isQuoteName); case "System.DateTime": return ExpressionLambdaToSqlCallDateTime(exp3, _tables, _selectColumnMap, tbtype, isQuoteName);
case "System.TimeSpan": return ExpressionLambdaToSqlCallTimeSpan(exp3, _tables, _selectColumnMap, tbtype, isQuoteName); case "System.TimeSpan": return ExpressionLambdaToSqlCallTimeSpan(exp3, _tables, _selectColumnMap, tbtype, isQuoteName);
case "System.Convert": return ExpressionLambdaToSqlCallConvert(exp3, _tables, _selectColumnMap, tbtype, isQuoteName);
} }
throw new Exception($"MySqlExpression 未现实函数表达式 {exp3} 解析"); throw new Exception($"MySqlExpression 未现实函数表达式 {exp3} 解析");
case ExpressionType.MemberAccess: case ExpressionType.MemberAccess:
@ -304,5 +318,6 @@ namespace FreeSql.Internal {
internal abstract string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName); internal abstract string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName);
internal abstract string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName); internal abstract string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName);
internal abstract string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName); internal abstract string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName);
internal abstract string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName);
} }
} }

View File

@ -248,7 +248,7 @@ namespace FreeSql.Internal.CommonProvider {
} }
var tran = TransactionCurrentThread; var tran = TransactionCurrentThread;
if (IsTracePerformance) logtxt += $" PrepareCommand_part1: {DateTime.Now.Subtract(dt).TotalMilliseconds}ms cmdParms: {cmdParms.Length}\r\n"; if (IsTracePerformance) logtxt += $" PrepareCommand_part1: {DateTime.Now.Subtract(dt).TotalMilliseconds}ms cmdParms: {cmd.Parameters.Count}\r\n";
if (tran != null) { if (tran != null) {
if (IsTracePerformance) dt = DateTime.Now; if (IsTracePerformance) dt = DateTime.Now;

View File

@ -207,7 +207,7 @@ namespace FreeSql.Internal.CommonProvider {
} }
} }
if (IsTracePerformance) logtxt += $" PrepareCommand_tran==null: {DateTime.Now.Subtract(dt).TotalMilliseconds}ms\r\n"; if (IsTracePerformance) logtxt += $" PrepareCommand_tran==null: {DateTime.Now.Subtract(dt).TotalMilliseconds}ms cmdParms: {cmd.Parameters.Count}\r\n";
return cmd; return cmd;
} }

View File

@ -65,7 +65,6 @@ namespace FreeSql.Internal.CommonProvider {
sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name));
++colidx; ++colidx;
} }
if (colidx == 0) return null;
sb.Append(") VALUES"); sb.Append(") VALUES");
_params = new DbParameter[colidx * _source.Count]; _params = new DbParameter[colidx * _source.Count];
var didx = 0; var didx = 0;

View File

@ -178,6 +178,7 @@ namespace FreeSql.Internal.CommonProvider {
var type = typeof(T1); var type = typeof(T1);
var map = new ReadAnonymousTypeInfo { Consturctor = type.GetConstructor(new Type[0]), ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties }; var map = new ReadAnonymousTypeInfo { Consturctor = type.GetConstructor(new Type[0]), ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties };
var field = new StringBuilder(); var field = new StringBuilder();
var dicfield = new Dictionary<string, bool>();
var tb = _tables.First(); var tb = _tables.First();
var index = 0; var index = 0;
var ps = typeof(T1).GetProperties(); var ps = typeof(T1).GetProperties();
@ -185,7 +186,11 @@ namespace FreeSql.Internal.CommonProvider {
var child = new ReadAnonymousTypeInfo { CsName = p.Name }; var child = new ReadAnonymousTypeInfo { CsName = p.Name };
if (tb.Table.ColumnsByCs.TryGetValue(p.Name, out var col)) { //普通字段 if (tb.Table.ColumnsByCs.TryGetValue(p.Name, out var col)) { //普通字段
if (index > 0) field.Append(", "); if (index > 0) field.Append(", ");
field.Append(tb.Alias).Append(".").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" as").Append(++index); var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
field.Append(tb.Alias).Append(".").Append(quoteName);
++index;
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
else dicfield.Add(quoteName, true);
} else { } else {
var tb2 = _tables.Where(a => a.Table.Type == p.PropertyType && a.Alias.Contains(p.Name)).FirstOrDefault(); var tb2 = _tables.Where(a => a.Table.Type == p.PropertyType && a.Alias.Contains(p.Name)).FirstOrDefault();
if (tb2 == null && ps.Where(pw => pw.PropertyType == p.PropertyType).Count() == 1) tb2 = _tables.Where(a => a.Table.Type == p.PropertyType).FirstOrDefault(); if (tb2 == null && ps.Where(pw => pw.PropertyType == p.PropertyType).Count() == 1) tb2 = _tables.Where(a => a.Table.Type == p.PropertyType).FirstOrDefault();
@ -194,7 +199,11 @@ namespace FreeSql.Internal.CommonProvider {
child.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties; child.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties;
foreach (var col2 in tb2.Table.Columns.Values) { foreach (var col2 in tb2.Table.Columns.Values) {
if (index > 0) field.Append(", "); if (index > 0) field.Append(", ");
field.Append(tb2.Alias).Append(".").Append(_commonUtils.QuoteSqlName(col2.Attribute.Name)).Append(" as").Append(++index); var quoteName = _commonUtils.QuoteSqlName(col2.Attribute.Name);
field.Append(tb2.Alias).Append(".").Append(quoteName);
++index;
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
else dicfield.Add(quoteName, true);
child.Childs.Add(new ReadAnonymousTypeInfo { CsName = col2.CsName }); child.Childs.Add(new ReadAnonymousTypeInfo { CsName = col2.CsName });
} }
} }

View File

@ -47,9 +47,8 @@ namespace FreeSql.Internal.CommonProvider {
default: throw new NotImplementedException($"未现实 {expCall.Method.Name}"); default: throw new NotImplementedException($"未现实 {expCall.Method.Name}");
} }
} }
return this;
} }
throw new NotImplementedException($"未现实 {exp}"); return this;
} }
public ISelect<T1> As(string alias) { public ISelect<T1> As(string alias) {

View File

@ -66,13 +66,10 @@ namespace FreeSql.Internal.CommonProvider {
if (cols.Any() == false) return this; if (cols.Any() == false) return this;
foreach (var col in cols) { foreach (var col in cols) {
if (col.Column.Attribute.IsNullable) { if (col.Column.Attribute.IsNullable) {
var repltype = col.Column.CsType; var replval = col.Column.Attribute.DbDefautValue;
if (repltype.FullName.StartsWith("System.Nullable`1[[System.")) repltype = repltype.GenericTypeArguments[0];
var replval = Activator.CreateInstance(repltype);
if (replval == null) continue; if (replval == null) continue;
var replname = _commonUtils.QuoteSqlName(col.Column.Attribute.Name); var replname = _commonUtils.QuoteSqlName(col.Column.Attribute.Name);
replval = _commonUtils.FormatSql("{0}", replval); expt = expt.Replace(replname, _commonUtils.IsNull(replname, _commonUtils.FormatSql("{0}", replval)));
expt = expt.Replace(replname, _commonUtils.IsNull(replname, replval));
} }
} }
_set.Append(", ").Append(_commonUtils.QuoteSqlName(cols.First().Column.Attribute.Name)).Append(" = ").Append(expt); _set.Append(", ").Append(_commonUtils.QuoteSqlName(cols.First().Column.Attribute.Name)).Append(" = ").Append(expt);

View File

@ -6,6 +6,7 @@ using System.Text;
namespace FreeSql.Internal.Model { namespace FreeSql.Internal.Model {
class ReadAnonymousTypeInfo { class ReadAnonymousTypeInfo {
public string CsName { get; set; } public string CsName { get; set; }
public Type CsType { get; set; }
public ConstructorInfo Consturctor { get; set; } public ConstructorInfo Consturctor { get; set; }
public ReadAnonymousTypeInfoConsturctorType ConsturctorType { get; set; } public ReadAnonymousTypeInfoConsturctorType ConsturctorType { get; set; }
public List<ReadAnonymousTypeInfo> Childs = new List<ReadAnonymousTypeInfo>(); public List<ReadAnonymousTypeInfo> Childs = new List<ReadAnonymousTypeInfo>();

View File

@ -13,6 +13,5 @@ namespace FreeSql.Internal.Model {
public string DbName { get; set; } public string DbName { get; set; }
public string DbOldName { get; set; } public string DbOldName { get; set; }
public string SelectFilter { get; set; } public string SelectFilter { get; set; }
public List<List<ColumnInfo>> Uniques { get; set; } = new List<List<ColumnInfo>>();
} }
} }

View File

@ -35,12 +35,22 @@ namespace FreeSql.Internal {
Name = p.Name, Name = p.Name,
DbType = tp.Value.dbtypeFull, DbType = tp.Value.dbtypeFull,
IsIdentity = false, IsIdentity = false,
IsNullable = tp.Value.isnullable ?? false, IsNullable = tp.Value.isnullable ?? true,
IsPrimary = false, IsPrimary = false,
}; };
if (string.IsNullOrEmpty(colattr.DbType) == false) colattr.DbType = colattr.DbType.ToUpper();
if (tp != null && tp.Value.isnullable == null) colattr.IsNullable = tp.Value.dbtypeFull.Contains("NOT NULL") == false;
if (string.IsNullOrEmpty(colattr.DbType) == false) colattr.IsNullable = colattr.DbType.Contains("NOT NULL") == false;
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name; if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)"; if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
if (colattr.DbType.IndexOf("NOT NULL") == -1 && tp?.isnullable == false) colattr.DbType += " NOT NULL"; if ((colattr.IsNullable == false || colattr.IsIdentity || colattr.IsPrimary) && colattr.DbType.Contains("NOT NULL") == false) colattr.DbType += " NOT NULL";
if (colattr.IsNullable == true && colattr.DbType.Contains("NOT NULL")) colattr.DbType = colattr.DbType.Replace("NOT NULL", "");
colattr.DbType = Regex.Replace(colattr.DbType, @"\([^\)]+\)", m => Regex.Replace(m.Groups[0].Value, @"\s", ""));
colattr.DbDefautValue = trytb.Properties[p.Name].GetValue(Activator.CreateInstance(trytb.Type));
if (colattr.DbDefautValue == null && p.PropertyType.FullName == "System.String") colattr.DbDefautValue = string.Empty;
if (colattr.DbDefautValue == null) colattr.DbDefautValue = Activator.CreateInstance(p.PropertyType.GenericTypeArguments.FirstOrDefault() ?? p.PropertyType);
if (colattr.DbDefautValue == null) colattr.DbDefautValue = "";
if (colattr.DbDefautValue.GetType().FullName == "System.DateTime") colattr.DbDefautValue = new DateTime(1970, 1, 1);
var col = new ColumnInfo { var col = new ColumnInfo {
Table = trytb, Table = trytb,
@ -52,6 +62,7 @@ namespace FreeSql.Internal {
trytb.ColumnsByCs.Add(p.Name, col); trytb.ColumnsByCs.Add(p.Name, col);
} }
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary).ToArray(); trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary).ToArray();
if (trytb.Primarys.Any() == false) trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsIdentity).ToArray();
_cacheGetTableByEntity.TryAdd(entity.FullName, trytb); _cacheGetTableByEntity.TryAdd(entity.FullName, trytb);
return trytb; return trytb;
} }
@ -122,22 +133,14 @@ namespace FreeSql.Internal {
if (prop == null) throw new Exception(string.Concat(type.FullName, " 没有定义属性 ", members[a])); if (prop == null) throw new Exception(string.Concat(type.FullName, " 没有定义属性 ", members[a]));
if (a < members.Length - 1) current = prop.GetValue(current); if (a < members.Length - 1) current = prop.GetValue(current);
} }
if (value == null || value == DBNull.Value) { prop.SetValue(current, GetDataReaderValue(prop.PropertyType, value), null);
prop.SetValue(current, null, null); }
return; internal static object GetDataReaderValue(Type type, object value) {
} if (value == null || value == DBNull.Value) return null;
var propType = prop.PropertyType; if (type.FullName.StartsWith("System.Nullable`1[")) type = type.GenericTypeArguments.First();
if (propType.FullName.StartsWith("System.Nullable`1[")) propType = propType.GenericTypeArguments.First(); if (type.IsEnum) return Enum.Parse(type, string.Concat(value));
if (propType.IsEnum) { if (type != value.GetType()) return Convert.ChangeType(value, type);
var valueStr = string.Concat(value); return value;
if (string.IsNullOrEmpty(valueStr) == false) prop.SetValue(current, Enum.Parse(propType, valueStr), null);
return;
}
if (propType != value.GetType()) {
prop.SetValue(current, Convert.ChangeType(value, propType), null);
return;
}
prop.SetValue(current, value, null);
} }
internal static string GetCsName(string name) { internal static string GetCsName(string name) {
name = Regex.Replace(name.TrimStart('@'), @"[^\w]", "_"); name = Regex.Replace(name.TrimStart('@'), @"[^\w]", "_");

View File

@ -106,7 +106,7 @@ namespace FreeSql.MySql {
sb.Append("CREATE TABLE IF NOT EXISTS ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ("); sb.Append("CREATE TABLE IF NOT EXISTS ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" (");
foreach (var tbcol in tb.Columns.Values) { foreach (var tbcol in tb.Columns.Values) {
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" "); sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
sb.Append(tbcol.Attribute.DbType.ToUpper()); sb.Append(tbcol.Attribute.DbType);
if (tbcol.Attribute.IsIdentity && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT"); if (tbcol.Attribute.IsIdentity && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
sb.Append(","); sb.Append(",");
} }
@ -143,10 +143,10 @@ where a.table_schema in ({0}) and a.table_name in ({1})".FormatMySql(isRenameTab
if (addcols.TryGetValue(column, out var trycol)) { if (addcols.TryGetValue(column, out var trycol)) {
if ((trycol.Attribute.DbType.IndexOf(" unsigned", StringComparison.CurrentCultureIgnoreCase) != -1) != is_unsigned || if ((trycol.Attribute.DbType.IndexOf(" unsigned", StringComparison.CurrentCultureIgnoreCase) != -1) != is_unsigned ||
Regex.Replace(trycol.Attribute.DbType, @"\([^\)]+\)", m => Regex.Replace(m.Groups[0].Value, @"\s", "")).StartsWith(sqlType, StringComparison.CurrentCultureIgnoreCase) == false || trycol.Attribute.DbType.StartsWith(sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
(trycol.Attribute.DbType.IndexOf("NOT NULL", StringComparison.CurrentCultureIgnoreCase) == -1) != is_nullable || trycol.Attribute.IsNullable != is_nullable ||
trycol.Attribute.IsIdentity != is_identity) { trycol.Attribute.IsIdentity != is_identity) {
sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(column)).Append(" ").Append(trycol.Attribute.DbType.ToUpper()); sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(column)).Append(" ").Append(trycol.Attribute.DbType);
if (trycol.Attribute.IsIdentity && trycol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT"); if (trycol.Attribute.IsIdentity && trycol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
sb.Append(";\r\n"); sb.Append(";\r\n");
} }
@ -156,12 +156,12 @@ where a.table_schema in ({0}) and a.table_name in ({1})".FormatMySql(isRenameTab
} }
foreach (var addcol in addcols.Values) { foreach (var addcol in addcols.Values) {
if (string.IsNullOrEmpty(addcol.Attribute.OldName) == false && surplus.ContainsKey(addcol.Attribute.OldName)) { //修改列名 if (string.IsNullOrEmpty(addcol.Attribute.OldName) == false && surplus.ContainsKey(addcol.Attribute.OldName)) { //修改列名
sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" CHANGE COLUMN ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.OldName)).Append(" ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.Name)).Append(" ").Append(addcol.Attribute.DbType.ToUpper()); sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" CHANGE COLUMN ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.OldName)).Append(" ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.Name)).Append(" ").Append(addcol.Attribute.DbType);
if (addcol.Attribute.IsIdentity && addcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT"); if (addcol.Attribute.IsIdentity && addcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
sb.Append(";\r\n"); sb.Append(";\r\n");
} else { //添加列 } else { //添加列
sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.Name)).Append(" ").Append(addcol.Attribute.DbType.ToUpper()); sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.Name)).Append(" ").Append(addcol.Attribute.DbType);
if (addcol.Attribute.IsIdentity && addcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT"); if (addcol.Attribute.IsIdentity && addcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
sb.Append(";\r\n"); sb.Append(";\r\n");
} }

View File

@ -36,9 +36,9 @@ namespace FreeSql.MySql {
} }
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, tbtype, isQuoteName); var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, tbtype, isQuoteName);
switch (exp.Member.Name) { switch (exp.Member.Name) {
case "Date": return $"cast(date_format({left}, '%Y-%m-%d') as datetime)"; case "Date": return $"cast(date_format({left},'%Y-%m-%d') as datetime)";
case "TimeOfDay": return $"(timestampdiff(microsecond, date_format({left}, '1970-1-1 %H:%i:%s.%f'), {left}) + 62135596800000000)"; case "TimeOfDay": return $"timestampdiff(microsecond, date_format({left},'%Y-%m-%d'), {left})";
case "DayOfWeek": return $"(dayofweek({left}) - 1)"; case "DayOfWeek": return $"(dayofweek({left})-1)";
case "Day": return $"dayofmonth({left})"; case "Day": return $"dayofmonth({left})";
case "DayOfYear": return $"dayofyear({left})"; case "DayOfYear": return $"dayofyear({left})";
case "Month": return $"month({left})"; case "Month": return $"month({left})";
@ -46,8 +46,8 @@ namespace FreeSql.MySql {
case "Hour": return $"hour({left})"; case "Hour": return $"hour({left})";
case "Minute": return $"minute({left})"; case "Minute": return $"minute({left})";
case "Second": return $"second({left})"; case "Second": return $"second({left})";
case "Millisecond": return $"floor(microsecond({left}) / 1000)"; case "Millisecond": return $"floor(microsecond({left})/1000)";
case "Ticks": return $"(timestampdiff(microsecond, '1970-1-1', {left}) * 10 + 621355968000000000)"; case "Ticks": return $"(timestampdiff(microsecond, '0001-1-1', {left})*10)";
} }
return null; return null;
} }
@ -94,7 +94,7 @@ namespace FreeSql.MySql {
case "Substring": case "Substring":
var substrArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); var substrArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString(); if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString();
else substrArgs1 += " + 1"; else substrArgs1 += "+1";
if (exp.Arguments.Count == 1) return $"substr({left}, {substrArgs1})"; if (exp.Arguments.Count == 1) return $"substr({left}, {substrArgs1})";
return $"substr({left}, {substrArgs1}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; return $"substr({left}, {substrArgs1}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "IndexOf": case "IndexOf":
@ -102,10 +102,10 @@ namespace FreeSql.MySql {
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") { if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") {
var locateArgs1 = ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName); var locateArgs1 = ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName);
if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString(); if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString();
else locateArgs1 += " + 1"; else locateArgs1 += "+1";
return $"(locate({left}, {indexOfFindStr}, {locateArgs1}) - 1)"; return $"(locate({left}, {indexOfFindStr}, {locateArgs1})-1)";
} }
return $"(locate({left}, {indexOfFindStr}) - 1)"; return $"(locate({left}, {indexOfFindStr})-1)";
case "PadLeft": case "PadLeft":
if (exp.Arguments.Count == 1) return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; if (exp.Arguments.Count == 1) return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
@ -167,74 +167,95 @@ namespace FreeSql.MySql {
internal override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) { internal override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp.Object == null) { if (exp.Object == null) {
switch (exp.Method.Name) { switch (exp.Method.Name) {
case "Compare": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}) - ({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "Compare": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} - ({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "DaysInMonth": return $"dayofmonth(last_day(concat({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}, '-', {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}, '-01')))"; case "DaysInMonth": return $"dayofmonth(last_day(concat({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}, '-', {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}, '-01')))";
case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "IsLeapYear": case "IsLeapYear":
var isLeapYearArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); var isLeapYearArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
return $"(({isLeapYearArgs1}) % 4 = 0 AND ({isLeapYearArgs1}) % 100 <> 0 OR ({isLeapYearArgs1}) % 400 = 0)"; return $"(({isLeapYearArgs1})%4=0 AND ({isLeapYearArgs1})%100 <> 0 OR ({isLeapYearArgs1})%400 = 0)";
case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)"; case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
case "ParseExact": case "ParseExact":
case "TryParse": case "TryParse":
case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)"; case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
} }
return null; } else {
} var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName);
var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName); var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); switch (exp.Method.Name) {
switch (exp.Method.Name) { case "Add": return $"date_add({left}, interval ({args1}) microsecond)";
case "Add": return $"date_add({left}, interval ({args1}) microsecond)"; case "AddDays": return $"date_add({left}, interval ({args1}) day)";
case "AddDays": return $"date_add({left}, interval ({args1}) day)"; case "AddHours": return $"date_add({left}, interval ({args1}) hour)";
case "AddHours": return $"date_add({left}, interval ({args1}) hour)"; case "AddMilliseconds": return $"date_add({left}, interval ({args1})*1000 microsecond)";
case "AddMilliseconds": return $"date_add({left}, interval ({args1}) * 1000 microsecond)"; case "AddMinutes": return $"date_add({left}, interval ({args1}) minute)";
case "AddMinutes": return $"date_add({left}, interval ({args1}) minute)"; case "AddMonths": return $"date_add({left}, interval ({args1}) month)";
case "AddMonths": return $"date_add({left}, interval ({args1}) month)"; case "AddSeconds": return $"date_add({left}, interval ({args1}) second)";
case "AddSeconds": return $"date_add({left}, interval ({args1}) second)"; case "AddTicks": return $"date_add({left}, interval ({args1})/10 microsecond)";
case "AddTicks": return $"date_add({left}, interval ({args1}) / 10 microsecond)"; case "AddYears": return $"date_add({left}, interval ({args1}) year)";
case "AddYears": return $"date_add({left}, interval ({args1}) year)"; case "Subtract":
case "Subtract": if (exp.Arguments[0].Type.FullName == "System.DateTime" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.DateTime")
if (exp.Arguments[0].Type.FullName == "System.DateTime" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.DateTime") return $"timestampdiff(microsecond, {args1}, {left})";
return $"timestampdiff(microsecond, {args1}, {left})"; if (exp.Arguments[0].Type.FullName == "System.TimeSpan" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.TimeSpan")
if (exp.Arguments[0].Type.FullName == "System.TimeSpan" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.TimeSpan") return $"date_sub({left}, interval ({args1}) microsecond)";
return $"date_sub({left}, interval ({args1}) microsecond)"; break;
break; case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "CompareTo": return $"(({left}) - ({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "CompareTo": return $"(({left}) - ({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "ToString": return $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')";
case "ToString": return $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')"; }
} }
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析"); throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
} }
internal override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) { internal override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp.Object == null) { if (exp.Object == null) {
switch (exp.Method.Name) { switch (exp.Method.Name) {
case "Compare": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}) - ({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "Compare": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}-({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "FromDays": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * {(long)1000000 * 60 * 60 * 24})"; case "FromDays": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*{(long)1000000 * 60 * 60 * 24})";
case "FromHours": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * {(long)1000000 * 60 * 60})"; case "FromHours": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*{(long)1000000 * 60 * 60})";
case "FromMilliseconds": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * 1000)"; case "FromMilliseconds": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*1000)";
case "FromMinutes": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * {(long)1000000 * 60})"; case "FromMinutes": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*{(long)1000000 * 60})";
case "FromSeconds": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * 1000000)"; case "FromSeconds": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*1000000)";
case "FromTicks": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} / 10)"; case "FromTicks": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})/10)";
case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as signed)"; case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as signed)";
case "ParseExact": case "ParseExact":
case "TryParse": case "TryParse":
case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as signed)"; case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as signed)";
} }
return null; } else {
} var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName);
var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName); var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); switch (exp.Method.Name) {
switch (exp.Method.Name) { case "Add": return $"({left}+{args1})";
case "Add": return $"({left} + {args1})"; case "Subtract": return $"({left}-({args1}))";
case "Subtract": return $"({left} - {args1})"; case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "CompareTo": return $"({left}-({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "CompareTo": return $"(({left}) - ({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "ToString": return $"cast({left} as char)";
case "ToString": return $"cast({left} as varchar)"; }
}
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
}
internal override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp.Object == null) {
switch (exp.Method.Name) {
case "ToBoolean": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} not in ('0','false'))";
case "ToByte": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as unsigned)";
case "ToChar": return $"substr(cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as char), 1, 1)";
case "ToDateTime": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
case "ToDecimal": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(36,18))";
case "ToDouble": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(32,16))";
case "ToInt16":
case "ToInt32":
case "ToInt64":
case "ToSByte": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as signed)";
case "ToSingle": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(14,7))";
case "ToString": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as char)";
case "ToUInt16":
case "ToUInt32":
case "ToUInt64": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as unsigned)";
}
} }
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析"); throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
} }
} }
} }

View File

@ -176,5 +176,28 @@ namespace FreeSql.PostgreSQL {
} }
throw new Exception($"PostgreSQLExpression 未现实函数表达式 {exp} 解析"); throw new Exception($"PostgreSQLExpression 未现实函数表达式 {exp} 解析");
} }
internal override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp.Object == null) {
switch (exp.Method.Name) {
case "ToBoolean": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} not in ('0','false'))";
case "ToByte": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as unsigned)";
case "ToChar": return $"substr(cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as char), 1, 1)";
case "ToDateTime": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
case "ToDecimal": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(36,18))";
case "ToDouble": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(32,16))";
case "ToInt16":
case "ToInt32":
case "ToInt64":
case "ToSByte": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as signed)";
case "ToSingle": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(14,7))";
case "ToString": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as char)";
case "ToUInt16":
case "ToUInt32":
case "ToUInt64": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as unsigned)";
}
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
}
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
}
} }
} }

View File

@ -85,7 +85,7 @@ namespace FreeSql.SqlServer {
if (_orm.Ado.ExecuteScalar(CommandType.Text, string.Format("select 1 from dbo.sysobjects where id = object_id(N'[{0}].[{1}]') and OBJECTPROPERTY(id, N'IsUserTable') = 1", tbname)) == null) { //表不存在 if (_orm.Ado.ExecuteScalar(CommandType.Text, string.Format("select 1 from dbo.sysobjects where id = object_id(N'[{0}].[{1}]') and OBJECTPROPERTY(id, N'IsUserTable') = 1", tbname)) == null) { //表不存在
if (tboldname != null && _orm.Ado.ExecuteScalar(CommandType.Text, string.Format("select 1 from dbo.sysobjects where id = object_id(N'[{0}].[{1}]') and OBJECTPROPERTY(id, N'IsUserTable') = 1", tboldname)) != null) { //旧表存在 if (tboldname != null && _orm.Ado.ExecuteScalar(CommandType.Text, string.Format("select 1 from dbo.sysobjects where id = object_id(N'[{0}].[{1}]') and OBJECTPROPERTY(id, N'IsUserTable') = 1", tboldname)) != null) { //旧表存在
//修改表名 //修改表名
sb.Append(_commonUtils.FormatSql("EXEC sp_rename {0}, {1};\r\n", _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}"), _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}"))); sb.Append(_commonUtils.FormatSql("EXEC sp_rename {0}, {1};\r\n", _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}"), _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")));
isRenameTable = true; isRenameTable = true;
@ -94,7 +94,7 @@ namespace FreeSql.SqlServer {
sb.Append("CREATE TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ("); sb.Append("CREATE TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" (");
foreach (var tbcol in tb.Columns.Values) { foreach (var tbcol in tb.Columns.Values) {
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" "); sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
sb.Append(tbcol.Attribute.DbType.ToUpper()); sb.Append(tbcol.Attribute.DbType);
if (tbcol.Attribute.IsIdentity && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)"); if (tbcol.Attribute.IsIdentity && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)");
if (tbcol.Attribute.IsPrimary) sb.Append(" primary key"); if (tbcol.Attribute.IsPrimary) sb.Append(" primary key");
sb.Append(","); sb.Append(",");
@ -126,39 +126,95 @@ left join sys.tables d on d.object_id = a.object_id
left join sys.schemas e on e.schema_id = d.schema_id left join sys.schemas e on e.schema_id = d.schema_id
where a.object_id in (object_id(N'[{0}].[{1}]'))", isRenameTable ? tboldname : tbname); where a.object_id in (object_id(N'[{0}].[{1}]'))", isRenameTable ? tboldname : tbname);
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
foreach (var row in ds) { var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a => new {
string column = string.Concat(row[0]); column = string.Concat(a[0]),
string sqlType = string.Concat(row[1]).ToLower(); sqlType = string.Concat(a[1]),
bool is_nullable = string.Concat(row[2]) == "1"; is_nullable = string.Concat(a[2]) == "1",
bool is_identity = string.Concat(row[3]) == "1"; is_identity = string.Concat(a[3]) == "1"
}, StringComparer.CurrentCultureIgnoreCase);
if (addcols.TryGetValue(column, out var trycol)) { var sbalter = new StringBuilder();
if (Regex.Replace(trycol.Attribute.DbType, @"\([^\)]+\)", m => Regex.Replace(m.Groups[0].Value, @"\s", "")).StartsWith(sqlType, StringComparison.CurrentCultureIgnoreCase) == false || var istmpatler = false;
(trycol.Attribute.DbType.IndexOf("NOT NULL", StringComparison.CurrentCultureIgnoreCase) == -1) != is_nullable || foreach (var tbcol in tb.Columns.Values) {
trycol.Attribute.IsIdentity != is_identity) { if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(column)).Append(" ").Append(trycol.Attribute.DbType.ToUpper()); string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) {
if (trycol.Attribute.IsIdentity && trycol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)"); if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
sb.Append(";\r\n"); tbcol.Attribute.IsNullable != tbstructcol.is_nullable ||
tbcol.Attribute.IsIdentity != tbstructcol.is_identity) {
istmpatler = true;
break;
} }
addcols.Remove(column); if (tbstructcol.column == tbcol.Attribute.OldName) {
} else //修改列名
surplus.Add(column, true); //记录剩余字段 sbalter.Append(_commonUtils.FormatSql("EXEC sp_rename {0}, {1}, 'COLUMN';\r\n", $"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.OldName}", tbcol.Attribute.Name));
}
continue;
}
//添加列
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType);
if (tbcol.Attribute.IsIdentity && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sbalter.Append(" identity(1,1)");
var addcoldbdefault = tb.Properties[tbcol.CsName].GetValue(Activator.CreateInstance(tb.Type));
if (tbcol.Attribute.IsNullable == false) addcoldbdefault = tbcol.Attribute.DbDefautValue;
if (addcoldbdefault != null) sbalter.Append(_commonUtils.FormatSql(" default({0})", addcoldbdefault));
sbalter.Append(";\r\n");
} }
foreach (var addcol in addcols.Values) { if (istmpatler == false) {
if (string.IsNullOrEmpty(addcol.Attribute.OldName) == false && surplus.ContainsKey(addcol.Attribute.OldName)) { //修改列名 sb.Append(sbalter);
sb.Append(_commonUtils.FormatSql("EXEC sp_rename {0}, {1}, 'COLUMN';\r\n", $"{tbname[0]}.{tbname[1]}.{addcol.Attribute.OldName}", addcol.Attribute.Name)); continue;
sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.Name)).Append(" ").Append(addcol.Attribute.DbType.ToUpper()); }
if (addcol.Attribute.IsIdentity && addcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)"); //创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
if (addcol.Attribute.DbType.ToUpper().Contains("NOT NULL")) sb.Append(_commonUtils.FormatSql(" default({0})", Activator.CreateInstance(addcol.CsType.GenericTypeArguments.FirstOrDefault() ?? addcol.CsType))); bool idents = false;
sb.Append(";\r\n"); var tablename = _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}");
var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}.TmpFreeSqlTmp_{tbname[1]}");
} else { //添加列 sb.Append("BEGIN TRANSACTION\r\n")
sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(addcol.Attribute.Name)).Append(" ").Append(addcol.Attribute.DbType.ToUpper()); .Append("SET QUOTED_IDENTIFIER ON\r\n")
if (addcol.Attribute.IsIdentity && addcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)"); .Append("SET ARITHABORT ON\r\n")
if (addcol.Attribute.DbType.ToUpper().Contains("NOT NULL")) sb.Append(_commonUtils.FormatSql(" default({0})", Activator.CreateInstance(addcol.CsType.GenericTypeArguments.FirstOrDefault() ?? addcol.CsType))); .Append("SET NUMERIC_ROUNDABORT OFF\r\n")
sb.Append(";\r\n"); .Append("SET CONCAT_NULL_YIELDS_NULL ON\r\n")
.Append("SET ANSI_NULLS ON\r\n")
.Append("SET ANSI_PADDING ON\r\n")
.Append("SET ANSI_WARNINGS ON\r\n")
.Append("COMMIT\r\n");
sb.Append("BEGIN TRANSACTION;\r\n");
//创建临时表
sb.Append("CREATE TABLE ").Append(tmptablename).Append(" (");
foreach (var tbcol in tb.Columns.Values) {
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
sb.Append(tbcol.Attribute.DbType);
if (tbcol.Attribute.IsIdentity && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)");
if (tbcol.Attribute.IsPrimary) sb.Append(" primary key");
sb.Append(",");
idents = idents || tbcol.Attribute.IsIdentity;
}
sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n");
sb.Append("ALTER TABLE ").Append(tmptablename).Append(" SET (LOCK_ESCALATION = TABLE);\r\n");
if (idents) sb.Append("SET IDENTITY_INSERT ").Append(tmptablename).Append(" ON;\r\n");
sb.Append("IF EXISTS(SELECT 1 FROM ").Append(tablename).Append(")\r\n");
sb.Append("\tEXEC('INSERT INTO ").Append(tmptablename).Append(" (");
foreach (var tbcol in tb.Columns.Values) {
if (tbstruct.ContainsKey(tbcol.Attribute.Name) || tbstruct.ContainsKey(tbcol.Attribute.OldName)) { //导入旧表存在的字段
sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
} }
} }
sb.Remove(sb.Length - 2, 2).Append(")\r\n\t\tSELECT ");
foreach (var tbcol in tb.Columns.Values) {
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) {
var insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) {
var tbcoldbtype = tbcol.Attribute.DbType.Split(' ').First();
insertvalue = $"cast({insertvalue} as {tbcoldbtype})";
}
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) {
insertvalue = $"isnull({insertvalue},{_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue).Replace("'", "''")})";
}
sb.Append(insertvalue).Append(", ");
}
}
sb.Remove(sb.Length - 2, 2).Append(" FROM ").Append(tablename).Append(" WITH (HOLDLOCK TABLOCKX)');\r\n");
if (idents) sb.Append("SET IDENTITY_INSERT ").Append(tmptablename).Append(" OFF;\r\n");
sb.Append("DROP TABLE ").Append(tablename).Append(";\r\n");
sb.Append("EXECUTE sp_rename N'").Append(tmptablename).Append("', N'").Append(tbname[1]).Append("', 'OBJECT' ;\r\n");
sb.Append("COMMIT;\r\n");
} }
return sb.Length == 0 ? null : sb.ToString(); return sb.Length == 0 ? null : sb.ToString();
} }

View File

@ -37,8 +37,8 @@ namespace FreeSql.SqlServer {
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, tbtype, isQuoteName); var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, tbtype, isQuoteName);
switch (exp.Member.Name) { switch (exp.Member.Name) {
case "Date": return $"convert(char(10),{left},120)"; case "Date": return $"convert(char(10),{left},120)";
case "TimeOfDay": return $"datediff(second, '1970-1-1 ' + convert(varchar, {left}, 14), {left})"; case "TimeOfDay": return $"datediff(second, convert(char(10),{left},120), {left})";
case "DayOfWeek": return $"(datepart(weekday, {left}) - 1)"; case "DayOfWeek": return $"(datepart(weekday, {left})-1)";
case "Day": return $"datepart(day, {left})"; case "Day": return $"datepart(day, {left})";
case "DayOfYear": return $"datepart(dayofyear, {left})"; case "DayOfYear": return $"datepart(dayofyear, {left})";
case "Month": return $"datepart(month, {left})"; case "Month": return $"datepart(month, {left})";
@ -46,8 +46,8 @@ namespace FreeSql.SqlServer {
case "Hour": return $"datepart(hour, {left})"; case "Hour": return $"datepart(hour, {left})";
case "Minute": return $"datepart(minute, {left})"; case "Minute": return $"datepart(minute, {left})";
case "Second": return $"datepart(second, {left})"; case "Second": return $"datepart(second, {left})";
case "Millisecond": return $"datepart(millisecond, {left})"; case "Millisecond": return $"(datepart(millisecond, {left})/1000)";
case "Ticks": return $"datediff(second, '1970-1-1', {left})"; case "Ticks": return $"(cast(datediff(second, '1970-1-1', {left}) as bigint)*10000000+621355968000000000)";
} }
return null; return null;
} }
@ -62,16 +62,16 @@ namespace FreeSql.SqlServer {
} }
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, tbtype, isQuoteName); var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, tbtype, isQuoteName);
switch (exp.Member.Name) { switch (exp.Member.Name) {
case "Days": return $"floor(({left}) / {60 * 60 * 24})"; case "Days": return $"floor(({left})/{60 * 60 * 24})";
case "Hours": return $"floor(({left}) / {60 * 60} % 24)"; case "Hours": return $"floor(({left})/{60 * 60}%24)";
case "Milliseconds": return $"(cast({left} as bigint) * 1000)"; case "Milliseconds": return $"(cast({left} as bigint)*1000)";
case "Minutes": return $"floor(({left}) / 60 % 60)"; case "Minutes": return $"floor(({left})/60%60)";
case "Seconds": return $"(({left}) % 60)"; case "Seconds": return $"(({left})%60)";
case "Ticks": return $"(cast({left} as bigint) * 10000000)"; case "Ticks": return $"(cast({left} as bigint)*10000000)";
case "TotalDays": return $"(({left}) / {60 * 60 * 24})"; case "TotalDays": return $"(({left})/{60 * 60 * 24})";
case "TotalHours": return $"(({left}) / {60 * 60})"; case "TotalHours": return $"(({left})/{60 * 60})";
case "TotalMilliseconds": return $"(cast({left} as bigint) * 1000)"; case "TotalMilliseconds": return $"(cast({left} as bigint)*1000)";
case "TotalMinutes": return $"(({left}) / 60)"; case "TotalMinutes": return $"(({left})/60)";
case "TotalSeconds": return $"({left})"; case "TotalSeconds": return $"({left})";
} }
return null; return null;
@ -85,22 +85,27 @@ namespace FreeSql.SqlServer {
case "Contains": case "Contains":
var args0Value = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); var args0Value = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
if (args0Value == "NULL") return $"({left}) IS NULL"; if (args0Value == "NULL") return $"({left}) IS NULL";
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar) + '%')")}"; if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar)+'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' + cast({args0Value} as nvarchar))")}"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar))")}";
if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}";
return $"({left}) LIKE ('%' + cast({args0Value} as nvarchar) + '%')"; return $"({left}) LIKE ('%'+cast({args0Value} as nvarchar)+'%')";
case "ToLower": return $"lower({left})"; case "ToLower": return $"lower({left})";
case "ToUpper": return $"upper({left})"; case "ToUpper": return $"upper({left})";
case "Substring": case "Substring":
var substrArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); var substrArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString(); if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString();
else substrArgs1 += " + 1"; else substrArgs1 += "+1";
if (exp.Arguments.Count == 1) return $"left({left}, {substrArgs1})"; if (exp.Arguments.Count == 1) return $"left({left}, {substrArgs1})";
return $"substring({left}, {substrArgs1}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; return $"substring({left}, {substrArgs1}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "IndexOf": case "IndexOf":
var indexOfFindStr = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); var indexOfFindStr = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") return $"(charindex({left}, {indexOfFindStr}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)} + 1) - 1)"; if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") {
return $"(charindex({left}, {indexOfFindStr}) - 1)"; var locateArgs1 = ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName);
if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString();
else locateArgs1 += "+1";
return $"(charindex({left}, {indexOfFindStr}, {locateArgs1})-1)";
}
return $"(charindex({left}, {indexOfFindStr})-1)";
case "PadLeft": case "PadLeft":
if (exp.Arguments.Count == 1) return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; if (exp.Arguments.Count == 1) return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; return $"lpad({left}, {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}, {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
@ -144,71 +149,93 @@ namespace FreeSql.SqlServer {
internal override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) { internal override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp.Object == null) { if (exp.Object == null) {
switch (exp.Method.Name) { switch (exp.Method.Name) {
case "Compare": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}) - ({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "Compare": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} - ({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "DaysInMonth": return $"datepart(day, dateadd(day, -1, dateadd(month, 1, cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as varchar) + '-' + cast({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)} as varchar) + '-1')))"; case "DaysInMonth": return $"datepart(day, dateadd(day, -1, dateadd(month, 1, cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as varchar) + '-' + cast({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)} as varchar) + '-1')))";
case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "IsLeapYear": case "IsLeapYear":
var isLeapYearArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); var isLeapYearArgs1 = ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
return $"(({isLeapYearArgs1}) % 4 = 0 AND ({isLeapYearArgs1}) % 100 <> 0 OR ({isLeapYearArgs1}) % 400 = 0)"; return $"(({isLeapYearArgs1})%4=0 AND ({isLeapYearArgs1})%100<>0 OR ({isLeapYearArgs1})%400=0)";
case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)"; case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
case "ParseExact": case "ParseExact":
case "TryParse": case "TryParse":
case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)"; case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
} }
return null; } else {
} var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName);
var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName); var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); switch (exp.Method.Name) {
switch (exp.Method.Name) { case "Add": return $"dateadd(second, {args1}, {left})";
case "Add": return $"dateadd(second, {args1}, {left})"; case "AddDays": return $"dateadd(day, {args1}, {left})";
case "AddDays": return $"dateadd(day, {args1}, {left})"; case "AddHours": return $"dateadd(hour, {args1}, {left})";
case "AddHours": return $"dateadd(hour, {args1}, {left})"; case "AddMilliseconds": return $"dateadd(second, ({args1})/1000, {left})";
case "AddMilliseconds": return $"dateadd(second, {args1} / 1000, {left})"; case "AddMinutes": return $"dateadd(minute, {args1}, {left})";
case "AddMinutes": return $"dateadd(minute, {args1}, {left})"; case "AddMonths": return $"dateadd(month, {args1}, {left})";
case "AddMonths": return $"dateadd(month, {args1}, {left})"; case "AddSeconds": return $"dateadd(second, {args1}, {left})";
case "AddSeconds": return $"dateadd(second, {args1}, {left})"; case "AddTicks": return $"dateadd(second, ({args1})/10000000, {left})";
case "AddTicks": return $"dateadd(second, {args1} / 10000000, {left})"; case "AddYears": return $"dateadd(year, {args1}, {left})";
case "AddYears": return $"dateadd(year, {args1}, {left})"; case "Subtract":
case "Subtract": if (exp.Arguments[0].Type.FullName == "System.DateTime" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.DateTime")
if (exp.Arguments[0].Type.FullName == "System.DateTime" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.DateTime") return $"datediff(second, {args1}, {left})";
return $"datediff(second, {args1}, {left})"; if (exp.Arguments[0].Type.FullName == "System.TimeSpan" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.TimeSpan")
if (exp.Arguments[0].Type.FullName == "System.TimeSpan" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.TimeSpan") return $"dateadd(second, {args1}*-1, {left})";
return $"dateadd(second, {args1} * -1, {left})"; break;
break; case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "CompareTo": return $"(({left}) - ({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "CompareTo": return $"(({left}) - ({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "ToString": return $"convert(varchar, {left}, 121)";
case "ToString": return $"convert(varchar, {left}, 121)"; }
} }
throw new Exception($"SqlServerExpression 未现实函数表达式 {exp} 解析"); throw new Exception($"SqlServerExpression 未现实函数表达式 {exp} 解析");
} }
internal override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) { internal override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp.Object == null) { if (exp.Object == null) {
switch (exp.Method.Name) { switch (exp.Method.Name) {
case "Compare": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}) - ({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "Compare": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}-({ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "Equals": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} = {ExpressionLambdaToSql(exp.Arguments[1], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "FromDays": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * {60 * 60 * 24})"; case "FromDays": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*{60 * 60 * 24})";
case "FromHours": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * {60 * 60})"; case "FromHours": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*{60 * 60})";
case "FromMilliseconds": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} / 1000)"; case "FromMilliseconds": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})/1000)";
case "FromMinutes": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} * 60)"; case "FromMinutes": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})*60)";
case "FromSeconds": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "FromSeconds": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "FromTicks": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} / 10000000)"; case "FromTicks": return $"(({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})/10000000)";
case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as bigint)"; case "Parse": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as bigint)";
case "ParseExact": case "ParseExact":
case "TryParse": case "TryParse":
case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as bigint)"; case "TryParseExact": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as bigint)";
} }
return null; } else {
var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName);
var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName);
switch (exp.Method.Name) {
case "Add": return $"({left}+{args1})";
case "Subtract": return $"({left}-({args1}))";
case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})";
case "CompareTo": return $"({left}-({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))";
case "ToString": return $"cast({left} as varchar)";
}
} }
var left = ExpressionLambdaToSql(exp.Object, _tables, _selectColumnMap, tbtype, isQuoteName); throw new Exception($"SqlServerExpression 未现实函数表达式 {exp} 解析");
var args1 = exp.Arguments.Count == 0 ? null : ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName); }
switch (exp.Method.Name) { internal override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, SelectTableInfoType tbtype, bool isQuoteName) {
case "Add": return $"({left} + {args1})"; if (exp.Object == null) {
case "Subtract": return $"({left} - {args1})"; switch (exp.Method.Name) {
case "Equals": return $"({left} = {ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)})"; case "ToBoolean": return $"({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} not in ('0','false'))";
case "CompareTo": return $"(({left}) - ({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)}))"; case "ToByte": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as tinyint)";
case "ToString": return $"cast({left} as varchar)"; case "ToChar": return $"substring(cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as nvarchar), 1, 1)";
case "ToDateTime": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as datetime)";
case "ToDecimal": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(36,18))";
case "ToDouble": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(32,16))";
case "ToInt16": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as smallint)";
case "ToInt32": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as int)";
case "ToInt64": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as bigint)";
case "ToSByte": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as tinyint)";
case "ToSingle": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as decimal(14,7))";
case "ToString": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as nvarchar)";
case "ToUInt16": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as smallint)";
case "ToUInt32": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as int)";
case "ToUInt64": return $"cast({ExpressionLambdaToSql(exp.Arguments[0], _tables, _selectColumnMap, tbtype, isQuoteName)} as bigint)";
}
} }
throw new Exception($"SqlServerExpression 未现实函数表达式 {exp} 解析"); throw new Exception($"SqlServerExpression 未现实函数表达式 {exp} 解析");
} }