- 修复 Ado.Query 查询字段重复时报错;#162 #165 #161 - 增加 FreeSql.Provider.MsAccess 支持 Access 数据库操作,已通过 2003/2007 版本测试;

This commit is contained in:
28810
2019-12-24 06:16:52 +08:00
parent d5ed1c8a30
commit a92c279c72
69 changed files with 10380 additions and 207 deletions

View File

@ -1014,6 +1014,83 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
a.Id,
a.Clicks
});
var sqltmp12 = g.mysql.Select<WF_Task>()
.Where(t => t.IsFinished && (t.AuditorId == "1" || t.AuditorId == "1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3"))
.GroupBy(t => new { t.ProcessId, t.NodeId, t.NodeName })
.ToSql(t => new WF_TaskGroupBy
{
TaskId = t.Max(t.Value.Id),
TaskType = t.Max(t.Value.Type),
ProcessId = t.Key.ProcessId,
NodeId = t.Key.NodeId,
NodeName = t.Key.NodeName
}, FieldAliasOptions.AsProperty);
var groupsql12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => type == typeof(WF_TaskGroupBy) ? $"( {sqltmp12} )" : null)
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToSql((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
LEFT JOIN `WF_ProcessInstance` b ON b.`Id` = a.`ProcessId`
WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql12);
var grouplist12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => $"( {sqltmp12} )")
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToList((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
}
[Table(DisableSyncStructure = true)]
class WF_TaskGroupBy
{
public int TaskId { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
}
class WF_Task
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int Type { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
public string AuditorId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
}
class WF_ProcessInstance
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
public bool EnabledMark { get; set; }
}
public class TestInclude_OneToManyModel1

View File

@ -1025,6 +1025,83 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
a.Id,
a.Clicks
});
var sqltmp12 = g.mysql.Select<WF_Task>()
.Where(t => t.IsFinished && (t.AuditorId == "1" || t.AuditorId == "1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3"))
.GroupBy(t => new { t.ProcessId, t.NodeId, t.NodeName })
.ToSql(t => new WF_TaskGroupBy
{
TaskId = t.Max(t.Value.Id),
TaskType = t.Max(t.Value.Type),
ProcessId = t.Key.ProcessId,
NodeId = t.Key.NodeId,
NodeName = t.Key.NodeName
}, FieldAliasOptions.AsProperty);
var groupsql12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => type == typeof(WF_TaskGroupBy) ? $"( {sqltmp12} )" : null)
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToSql((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
LEFT JOIN `WF_ProcessInstance` b ON b.`Id` = a.`ProcessId`
WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql12);
var grouplist12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => $"( {sqltmp12} )")
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToList((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
}
[Table(DisableSyncStructure = true)]
class WF_TaskGroupBy
{
public int TaskId { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
}
class WF_Task
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int Type { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
public string AuditorId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
}
class WF_ProcessInstance
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
public bool EnabledMark { get; set; }
}
public class TestInclude_OneToManyModel1

View File

@ -31,6 +31,7 @@
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MsAccess\FreeSql.Provider.MsAccess.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySql\FreeSql.Provider.MySql.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />

View File

@ -0,0 +1,93 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccess
{
public class MsAccessDeleteTest
{
IDelete<Topic> delete => g.msaccess.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Table(Name = "tb_topic22211")]
class Topic
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int? Clicks { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
[Fact]
public void Dywhere()
{
Assert.Null(g.msaccess.Delete<Topic>().ToSql());
var sql = g.msaccess.Delete<Topic>(new[] { 1, 2 }).ToSql();
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1 OR [Id] = 2)", sql);
sql = g.msaccess.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
sql = g.msaccess.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1 OR [Id] = 2)", sql);
sql = g.msaccess.Delete<Topic>(new { id = 1 }).ToSql();
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
}
[Fact]
public void Where()
{
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
sql = delete.Where("id = @id", new { id = 1 }).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM [tb_topic22211] WHERE (id = @id)", sql);
var item = new Topic { Id = 1, Title = "newtitle" };
sql = delete.Where(item).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
sql = delete.Where(items).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
}
[Fact]
public void ExecuteAffrows()
{
var id = g.msaccess.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteIdentity();
Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows());
}
[Fact]
public void ExecuteDeleted()
{
//var item = g.msaccess.Delete<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
}
[Fact]
public void AsTable()
{
Assert.Null(g.msaccess.Delete<Topic>().AsTable(a => "TopicAsTable").ToSql());
var sql = g.msaccess.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM [TopicAsTable] WHERE ([Id] = 1 OR [Id] = 2)", sql);
sql = g.msaccess.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM [TopicAsTable] WHERE ([Id] = 1)", sql);
sql = g.msaccess.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM [TopicAsTable] WHERE ([Id] = 1 OR [Id] = 2)", sql);
sql = g.msaccess.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM [TopicAsTable] WHERE ([Id] = 1)", sql);
}
}
}

View File

@ -0,0 +1,141 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccess
{
public class MsAccessInsertTest
{
IInsert<Topic> insert => g.msaccess.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Table(Name = "tb_topic")]
class Topic
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int? Clicks { get; set; }
public int TypeGuid { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
[Fact]
public void AppendData()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Parse("2019-09-19 20:09:37") });
var sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items.First()).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title], [CreateTime]) VALUES(0, 'newtitle0', '2019-09-19 20:09:37')", sql);
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title], [CreateTime]) VALUES(0, 'newtitle0', '2019-09-19 20:09:37'), (100, 'newtitle1', '2019-09-19 20:09:37'), (200, 'newtitle2', '2019-09-19 20:09:37'), (300, 'newtitle3', '2019-09-19 20:09:37'), (400, 'newtitle4', '2019-09-19 20:09:37'), (500, 'newtitle5', '2019-09-19 20:09:37'), (600, 'newtitle6', '2019-09-19 20:09:37'), (700, 'newtitle7', '2019-09-19 20:09:37'), (800, 'newtitle8', '2019-09-19 20:09:37'), (900, 'newtitle9', '2019-09-19 20:09:37')", sql);
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Title]) VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql);
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).AppendData(items).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title]) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
}
[Fact]
public void InsertColumns()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Title]) VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql);
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title]) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
}
[Fact]
public void IgnoreColumns()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
var sql = insert.AppendData(items).IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title]) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime, a.TypeGuid }).ToSql();
Assert.Equal("INSERT INTO [tb_topic]([Clicks]) VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
g.msaccess.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
var itemsIgnore = new List<TopicIgnore>();
for (var a = 0; a < 32; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
g.msaccess.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
Assert.Equal(32, itemsIgnore.Count);
Assert.Equal(32, g.msaccess.Select<TopicIgnore>().Where(a => a.Title == null).Count());
}
[Table(Name = "tb_topicIgnoreColumns")]
class TopicIgnore
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int Clicks { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
[Fact]
public void ExecuteAffrows()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows());
Assert.Equal(10, insert.AppendData(items).ExecuteAffrows());
//items = Enumerable.Range(0, 9989).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
//Assert.Equal(9989, g.msaccess.Insert<Topic>(items).ExecuteAffrows());
}
[Fact]
public void ExecuteIdentity()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity());
//items = Enumerable.Range(0, 9999).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
//var lastId = g.sqlite.Select<Topic>().Max(a => a.Id);
//Assert.NotEqual(lastId, g.msaccess.Insert<Topic>(items).ExecuteIdentity());
}
[Fact]
public void AsTable()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Parse("2019-09-19 20:01:51") });
var sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items.First()).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title], [CreateTime]) VALUES(0, 'newtitle0', '2019-09-19 20:01:51')", sql);
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title], [CreateTime]) VALUES(0, 'newtitle0', '2019-09-19 20:01:51'), (100, 'newtitle1', '2019-09-19 20:01:51'), (200, 'newtitle2', '2019-09-19 20:01:51'), (300, 'newtitle3', '2019-09-19 20:01:51'), (400, 'newtitle4', '2019-09-19 20:01:51'), (500, 'newtitle5', '2019-09-19 20:01:51'), (600, 'newtitle6', '2019-09-19 20:01:51'), (700, 'newtitle7', '2019-09-19 20:01:51'), (800, 'newtitle8', '2019-09-19 20:01:51'), (900, 'newtitle9', '2019-09-19 20:01:51')", sql);
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).InsertColumns(a => a.Title).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Title]) VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql);
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
sql = insert.IgnoreColumns(a => new { a.Title, a.TypeGuid }).InsertColumns(a => a.Title).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Title]) VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql);
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.Title, a.TypeGuid }).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks]) VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,141 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccess
{
public class MsAccessUpdateTest
{
IUpdate<Topic> update => g.msaccess.Update<Topic>();
[Table(Name = "tb_topic")]
class Topic
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int? Clicks { get; set; }
public int TypeGuid { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
[Fact]
public void Dywhere()
{
Assert.Null(g.msaccess.Update<Topic>().ToSql());
Assert.Equal("UPDATE [tb_topic] SET title='test' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.msaccess.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
Assert.Equal("UPDATE [tb_topic] SET title='test1' \r\nWHERE ([Id] = 1)", g.msaccess.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
Assert.Equal("UPDATE [tb_topic] SET title='test1' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.msaccess.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").ToSql());
Assert.Equal("UPDATE [tb_topic] SET title='test1' \r\nWHERE ([Id] = 1)", g.msaccess.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").ToSql());
}
[Fact]
public void SetSource()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = NULL, [Title] = 'newtitle', [CreateTime] = '1970-01-01 00:00:00' WHERE ([Id] = 1)", sql);
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
items[0].Clicks = null;
sql = update.SetSource(items).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = CASE [Id] WHEN 1 THEN NULL WHEN 2 THEN 100 WHEN 3 THEN 200 WHEN 4 THEN 300 WHEN 5 THEN 400 WHEN 6 THEN 500 WHEN 7 THEN 600 WHEN 8 THEN 700 WHEN 9 THEN 800 WHEN 10 THEN 900 END, [Title] = CASE [Id] WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END, [CreateTime] = CASE [Id] WHEN 1 THEN '1970-01-01 00:00:00' WHEN 2 THEN '1970-01-01 00:00:00' WHEN 3 THEN '1970-01-01 00:00:00' WHEN 4 THEN '1970-01-01 00:00:00' WHEN 5 THEN '1970-01-01 00:00:00' WHEN 6 THEN '1970-01-01 00:00:00' WHEN 7 THEN '1970-01-01 00:00:00' WHEN 8 THEN '1970-01-01 00:00:00' WHEN 9 THEN '1970-01-01 00:00:00' WHEN 10 THEN '1970-01-01 00:00:00' END WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
sql = update.SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Title] = CASE [Id] WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
sql = update.SetSource(items).IgnoreColumns(a => a.TypeGuid).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [CreateTime] = '2020-01-01 00:00:00' WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Title] = 'newtitle' WHERE ([Id] = 1)", sql);
}
[Fact]
public void UpdateColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).UpdateColumns(a => a.Title).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Title] = 'newtitle' WHERE ([Id] = 1)", sql);
}
[Fact]
public void Set()
{
var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Title] = 'newtitle' WHERE ([Id] = 1)", sql);
sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Title] = 'newtitle', [CreateTime] = '2020-01-01 00:00:00' WHERE ([Id] = 1)", sql);
sql = update.Set(a => a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = iif(isnull([Clicks]), 0, [Clicks]) * 10 / 1 WHERE ([Id] = 1)", sql);
sql = update.Set(a => a.Id - 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Id] = ([Id] - 10) WHERE ([Id] = 1)", sql);
int incrv = 10;
sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = iif(isnull([Clicks]), 0, [Clicks]) * 10 / 1 WHERE ([Id] = 1)", sql);
sql = update.Set(a => a.Id - incrv).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Id] = ([Id] - 10) WHERE ([Id] = 1)", sql);
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = [Clicks] * 10 / 1 WHERE ([Id] = 1)", sql);
sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Id] = 10 WHERE ([Id] = 1)", sql);
}
[Fact]
public void SetRaw()
{
var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + ?", new { incrClick = 1 }).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET clicks = clicks + ? WHERE ([Id] = 1)", sql);
}
[Fact]
public void Where()
{
var sql = update.Where(a => a.Id == 1).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE ([Id] = 1)", sql);
sql = update.Where("id = ?", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE (id = ?)", sql);
var item = new Topic { Id = 1, Title = "newtitle" };
sql = update.Where(item).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE ([Id] = 1)", sql);
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
sql = update.Where(items).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
}
[Fact]
public void ExecuteAffrows()
{
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
var time = DateTime.Now;
var items222 = g.msaccess.Select<Topic>().Where(a => a.CreateTime > Convert.ToDateTime(time)).Limit(10).ToList();
update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
update.SetSource(items).NoneParameter().ExecuteAffrows();
}
[Fact]
public void AsTable()
{
Assert.Null(g.msaccess.Update<Topic>().ToSql());
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.msaccess.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1)", g.msaccess.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.msaccess.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1)", g.msaccess.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
using FreeSql.DataAnnotations;
using System;
using System.Numerics;
using Xunit;
namespace FreeSql.Tests.MsAccessMapType
{
public class DateTimeOffSetTest
{
class DateTimeOffSetTestMap
{
public Guid id { get; set; }
[Column(MapType = typeof(DateTime))]
public DateTimeOffset dtos_to_dt { get; set; }
[Column(MapType = typeof(DateTime))]
public DateTimeOffset? dtosnullable_to_dt { get; set; }
}
[Fact]
public void DateTimeToDateTimeOffSet()
{
//insert
var orm = g.msaccess;
var item = new DateTimeOffSetTestMap { dtos_to_dt = DateTimeOffset.Now, dtosnullable_to_dt = DateTimeOffset.Now };
Assert.Equal(1, orm.Insert<DateTimeOffSetTestMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
//update all
item.dtos_to_dt = DateTimeOffset.Now;
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
//update set
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows());
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
//delete
Assert.Equal(1, orm.Delete<DateTimeOffSetTestMap>().Where(a => a.id == item.id).ExecuteAffrows());
Assert.Null(orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First());
}
}
}

View File

@ -0,0 +1,261 @@
using FreeSql.DataAnnotations;
using System;
using System.Numerics;
using Xunit;
namespace FreeSql.Tests.MsAccessMapType
{
public class EnumTest
{
class EnumTestMap
{
public Guid id { get; set; }
[Column(MapType = typeof(string))]
public ToStringMapEnum enum_to_string { get; set; }
[Column(MapType = typeof(string))]
public ToStringMapEnum? enumnullable_to_string { get; set; }
[Column(MapType = typeof(int))]
public ToStringMapEnum enum_to_int { get; set; }
[Column(MapType = typeof(int?))]
public ToStringMapEnum? enumnullable_to_int { get; set; }
}
public enum ToStringMapEnum { <EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, abc, <EFBFBD><EFBFBD><EFBFBD><EFBFBD> }
[Fact]
public void EnumToString()
{
//insert
var orm = g.msaccess;
var item = new EnumTestMap { };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
//update all
item.enum_to_string = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
item.enum_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
//update set
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
//delete
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void EnumNullableToString()
{
//insert
var orm = g.msaccess;
var item = new EnumTestMap { };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Null(find.enumnullable_to_string);
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
//update all
item.enumnullable_to_string = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
item.enumnullable_to_string = null;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Null(find.enumnullable_to_string);
//update set
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.enumnullable_to_string);
//delete
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void EnumToInt()
{
//insert
var orm = g.msaccess;
var item = new EnumTestMap { };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_int, find.enum_to_int);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_int, find.enum_to_int);
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
//update all
item.enum_to_int = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_int, find.enum_to_int);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
item.enum_to_int = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_int, find.enum_to_int);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
//update set
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
//delete
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void EnumNullableToInt()
{
//insert
var orm = g.msaccess;
var item = new EnumTestMap { };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
Assert.Null(find.enumnullable_to_int);
item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_int);
//update all
item.enumnullable_to_int = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_int);
item.enumnullable_to_int = null;
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
Assert.Null(find.enumnullable_to_int);
//update set
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, ToStringMapEnum.abc).ExecuteAffrows());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_int);
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, null).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First());
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.enumnullable_to_int);
//delete
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows());
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
}
}
}

View File

@ -0,0 +1,570 @@
using FreeSql.DataAnnotations;
using System;
using System.Numerics;
using Xunit;
namespace FreeSql.Tests.MsAccessMapType
{
public class ToStringTest
{
class ToStringMap
{
public Guid id { get; set; }
[Column(MapType = typeof(string))]
public TimeSpan timespan_to_string { get; set; }
[Column(MapType = typeof(string))]
public TimeSpan? timespannullable_to_string { get; set; }
[Column(MapType = typeof(string))]
public DateTime datetime_to_string { get; set; }
[Column(MapType = typeof(string))]
public DateTime? datetimenullable_to_string { get; set; }
[Column(MapType = typeof(string))]
public Guid guid_to_string { get; set; }
[Column(MapType = typeof(string))]
public Guid? guidnullable_to_string { get; set; }
[Column(MapType = typeof(string))]
public ToStringMapEnum enum_to_string { get; set; }
[Column(MapType = typeof(string))]
public ToStringMapEnum? enumnullable_to_string { get; set; }
[Column(MapType = typeof(string))]
public BigInteger biginteger_to_string { get; set; }
[Column(MapType = typeof(string))]
public BigInteger? bigintegernullable_to_string { get; set; }
}
public enum ToStringMapEnum { <EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, abc, <EFBFBD><EFBFBD><EFBFBD><EFBFBD> }
[Fact]
public void Enum1()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
item = new ToStringMap { enum_to_string = ToStringMapEnum.abc };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
//update all
item.enum_to_string = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
item.enum_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enum_to_string, find.enum_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
//delete
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void EnumNullable()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Null(find.enumnullable_to_string);
item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
//update all
item.enumnullable_to_string = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
item.enumnullable_to_string = null;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
Assert.Null(find.enumnullable_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.enumnullable_to_string);
//delete
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void BigInteger1()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 0).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
Assert.Equal(0, find.biginteger_to_string);
item = new ToStringMap { biginteger_to_string = 100 };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 100).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
Assert.Equal(100, find.biginteger_to_string);
//update all
item.biginteger_to_string = 200;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 200).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
Assert.Equal(200, find.biginteger_to_string);
item.biginteger_to_string = 205;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
Assert.Equal(205, find.biginteger_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 522).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(522, find.biginteger_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 10005).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(10005, find.biginteger_to_string);
//delete
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).ExecuteAffrows());
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).ExecuteAffrows());
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void BigIntegerNullable()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
Assert.Null(find.bigintegernullable_to_string);
item = new ToStringMap { bigintegernullable_to_string = 101 };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
Assert.Equal(101, find.bigintegernullable_to_string);
//update all
item.bigintegernullable_to_string = 2004;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
Assert.Equal(2004, find.bigintegernullable_to_string);
item.bigintegernullable_to_string = null;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
Assert.Null(find.bigintegernullable_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(998, find.bigintegernullable_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.bigintegernullable_to_string);
//delete
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows());
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void TimeSpan1()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
Assert.Equal(TimeSpan.Zero, find.timespan_to_string);
item = new ToStringMap { timespan_to_string = TimeSpan.FromDays(1) };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
Assert.Equal(TimeSpan.FromDays(1), find.timespan_to_string);
//update all
item.timespan_to_string = TimeSpan.FromHours(10);
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
Assert.Equal(TimeSpan.FromHours(10), find.timespan_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespan_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(TimeSpan.FromHours(11), find.timespan_to_string);
//delete
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void TimeSpanNullable()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
Assert.Null(find.timespannullable_to_string);
item = new ToStringMap { timespannullable_to_string = TimeSpan.FromDays(1) };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
Assert.Equal(TimeSpan.FromDays(1), find.timespannullable_to_string);
//update all
item.timespannullable_to_string = TimeSpan.FromHours(10);
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
Assert.Equal(TimeSpan.FromHours(10), find.timespannullable_to_string);
item.timespannullable_to_string = null;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
Assert.Null(find.timespannullable_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(TimeSpan.FromHours(11), find.timespannullable_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, null).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.timespannullable_to_string);
//delete
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void DateTime1()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
Assert.Equal(DateTime.MinValue, find.datetime_to_string);
item = new ToStringMap { datetime_to_string = DateTime.Parse("2000-1-1") };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetime_to_string);
//update all
item.datetime_to_string = DateTime.Parse("2000-1-11");
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetime_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetime_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetime_to_string);
//delete
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void DateTimeNullable()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
Assert.Null(find.datetimenullable_to_string);
item = new ToStringMap { datetimenullable_to_string = DateTime.Parse("2000-1-1") };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetimenullable_to_string);
//update all
item.datetimenullable_to_string = DateTime.Parse("2000-1-11");
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetimenullable_to_string);
item.datetimenullable_to_string = null;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
Assert.Null(find.datetimenullable_to_string);
//update set
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetimenullable_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, null).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.datetimenullable_to_string);
//delete
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void Guid1()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == Guid.Empty).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guid_to_string, find.guid_to_string);
Assert.Equal(Guid.Empty, find.guid_to_string);
var newid = Guid.NewGuid();
item = new ToStringMap { guid_to_string = newid };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guid_to_string, find.guid_to_string);
Assert.Equal(newid, find.guid_to_string);
//update all
newid = Guid.NewGuid();
item.guid_to_string = newid;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guid_to_string, find.guid_to_string);
Assert.Equal(newid, find.guid_to_string);
//update set
newid = Guid.NewGuid();
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guid_to_string, newid).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(newid, find.guid_to_string);
//delete
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
[Fact]
public void GuidNullable()
{
//insert
var orm = g.msaccess;
var item = new ToStringMap { };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
Assert.Null(find.guidnullable_to_string);
var newid = Guid.NewGuid();
item = new ToStringMap { guidnullable_to_string = newid };
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
Assert.Equal(newid, find.guidnullable_to_string);
//update all
newid = Guid.NewGuid();
item.guidnullable_to_string = newid;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
Assert.Equal(newid, find.guidnullable_to_string);
item.guidnullable_to_string = null;
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
Assert.Null(find.guidnullable_to_string);
//update set
newid = Guid.NewGuid();
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal(newid, find.guidnullable_to_string);
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows());
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Null(find.guidnullable_to_string);
//delete
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows());
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
}
}
}

View File

@ -0,0 +1,81 @@
using FreeSql.DataAnnotations;
using System;
using Xunit;
namespace FreeSql.Tests.MsAccess
{
public class MsAccessAdoTest
{
[Fact]
public void Pool()
{
var t1 = g.msaccess.Ado.MasterPool.StatisticsFullily;
}
[Fact]
public void SlavePools()
{
var t2 = g.msaccess.Ado.SlavePools.Count;
}
[Fact]
public void ExecuteReader()
{
}
[Fact]
public void ExecuteArray()
{
}
[Fact]
public void ExecuteNonQuery()
{
}
[Fact]
public void ExecuteScalar()
{
}
[Fact]
public void Query()
{
var t0 = g.msaccess.Ado.Query<testallDto>("select * from [song]");
var t1 = g.msaccess.Ado.Query<testallDto>("select id, url, create_time from [song]");
var t2 = g.msaccess.Ado.Query<testallDto>("select id, url, create_time from [song]");
var t3 = g.msaccess.Ado.Query<xxx>("select * from [song]");
var t4 = g.msaccess.Ado.Query<(int, string, string)>("select * from [song]");
var t5 = g.msaccess.Ado.Query<dynamic>("select * from [song]");
}
[Fact]
public void QueryMultipline()
{
//var t3 = g.msaccess.Ado.Query<xxx, (int, string, string), dynamic>("select * from song; select * from song; select * from song");
}
class xxx
{
public int Id { get; set; }
public string Path { get; set; }
public string Title2 { get; set; }
}
class testallDto
{
public int Id { get; set; }
public string Title { get; set; }
public string Url { get; set; }
public DateTime Test_time { get; set; }
public DateTime Create_time { get; set; }
public bool Is_deleted { get; set; }
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Xunit;
namespace FreeSql.Tests.MsAccess
{
public class MsAccessAopTest
{
class TestAuditValue
{
public Guid id { get; set; }
[Now]
public DateTime createtime { get; set; }
}
class NowAttribute: Attribute { }
[Fact]
public void AuditValue()
{
var date = DateTime.Now.Date;
var item = new TestAuditValue();
EventHandler<Aop.AuditValueEventArgs> audit = (s, e) =>
{
if (e.Property.GetCustomAttribute<NowAttribute>(false) != null)
e.Value = DateTime.Now.Date;
};
g.msaccess.Aop.AuditValue += audit;
g.msaccess.Insert(item).ExecuteAffrows();
g.msaccess.Aop.AuditValue -= audit;
Assert.Equal(item.createtime, date);
}
}
}

View File

@ -0,0 +1,307 @@
using FreeSql.DataAnnotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
namespace FreeSql.Tests.MsAccess
{
public class MsAccessCodeFirstTest
{
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>_<EFBFBD>ֶ<EFBFBD>()
{
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>>();
g.msaccess.CodeFirst.SyncStructure<<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>>();
var item = new <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
{
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = "<22><><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>",
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> = DateTime.Now
};
Assert.Equal(1, g.msaccess.Insert<<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>>().AppendData(item).ExecuteAffrows());
Assert.NotEqual(Guid.Empty, item.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>);
var item2 = g.msaccess.Select<<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>>().Where(a => a.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> == item.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
Assert.NotNull(item2);
Assert.Equal(item.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, item2.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>);
Assert.Equal(item.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, item2.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>);
}
class <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
{
[Column(IsPrimary = true)]
public Guid <EFBFBD><EFBFBD><EFBFBD><EFBFBD> { get; set; }
public string <EFBFBD><EFBFBD><EFBFBD><EFBFBD> { get; set; }
[Column(ServerTime = DateTimeKind.Local)]
public DateTime <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> { get; set; }
}
[Fact]
public void AddUniques()
{
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
g.msaccess.CodeFirst.SyncStructure<AddUniquesInfo>();
}
[Table(Name = "AddUniquesInfo2", OldName = "AddUniquesInfo")]
[Index("uk_phone", "phone", true)]
[Index("uk_group_index", "group,index", true)]
[Index("uk_group_index22", "group desc, index22", true)]
class AddUniquesInfo
{
public Guid id { get; set; }
public string phone { get; set; }
public string group { get; set; }
public int index { get; set; }
public string index22 { get; set; }
}
public class Topic
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime CreateTime { get; set; }
}
[Table(Name = "Comment")]
public class Comment
{
public Guid Id { get; set; }
public Guid TopicId { get; set; }
public virtual Topic Topic { get; set; }
public string Nickname { get; set; }
public string Content { get; set; }
public DateTime CreateTime { get; set; }
}
[Fact]
public void AddField()
{
//<2F><>һ<EFBFBD><D2BB> FreeSql.Repository <20><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>dotnet add package FreeSql.Repository
var topicRepository = g.msaccess.GetGuidRepository<Topic>();
var commentRepository = g.msaccess.GetGuidRepository<Comment>();
//<2F><><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var topic = topicRepository.Insert(new Topic
{
Title = "<22><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>1",
Content = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1",
CreateTime = DateTime.Now
});
//<2F><><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var comments = Enumerable.Range(0, 10).Select(a => new Comment
{
TopicId = topic.Id,
Nickname = $"<22>dz<EFBFBD>{a}",
Content = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{a}",
CreateTime = DateTime.Now
}).ToArray();
var affrows = commentRepository.Insert(comments);
var find = commentRepository.Select.Where(a => a.Topic.Title == "<22><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>1").ToList();
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
var id = g.msaccess.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
//var inserted = g.msaccess.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteInserted();
}
[Table(Name = "TopicAddField", OldName = "TopicAddField")]
public class TopicAddField
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public string name { get; set; }
[Column(DbType = "varchar(200) not null", OldName = "title2")]
public string title3223 { get; set; } = "10";
[Column(IsIgnore = true)]
public DateTime ct { get; set; } = DateTime.Now;
}
[Fact]
public void GetComparisonDDLStatements()
{
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<TableAllType>();
if (string.IsNullOrEmpty(sql) == false)
{
Assert.Equal(@"CREATE TABLE [tb_alltype] (
[Id] AUTOINCREMENT,
[Bool] BIT NOT NULL,
[SByte] DECIMAL(3,0) NOT NULL,
[Short] DECIMAL(6,0) NOT NULL,
[Int] DECIMAL(11,0) NOT NULL,
[Long] DECIMAL(20,0) NOT NULL,
[Byte] DECIMAL(3,0) NOT NULL,
[UShort] DECIMAL(5,0) NOT NULL,
[UInt] DECIMAL(10,0) NOT NULL,
[ULong] DECIMAL(20,0) NOT NULL,
[Double] DOUBLE NOT NULL,
[Float] SINGLE NOT NULL,
[Decimal] DECIMAL(10,2) NOT NULL,
[TimeSpan] TIME NOT NULL,
[DateTime] DATETIME NOT NULL,
[DateTimeOffSet] DATETIME NOT NULL,
[Bytes] BINARY(255),
[String] VARCHAR(255),
[Guid] VARCHAR(36) NOT NULL,
[BoolNullable] BIT,
[SByteNullable] DECIMAL(3,0),
[ShortNullable] DECIMAL(6,0),
[IntNullable] DECIMAL(11,0),
[testFielLongNullable] DECIMAL(20,0),
[ByteNullable] DECIMAL(3,0),
[UShortNullable] DECIMAL(5,0),
[UIntNullable] DECIMAL(10,0),
[ULongNullable] DECIMAL(20,0),
[DoubleNullable] DOUBLE,
[FloatNullable] SINGLE,
[DecimalNullable] DECIMAL(10,2),
[TimeSpanNullable] TIME,
[DateTimeNullable] DATETIME,
[DateTimeOffSetNullable] DATETIME,
[GuidNullable] VARCHAR(36),
[Enum1] DECIMAL(11,0) NOT NULL,
[Enum1Nullable] DECIMAL(11,0),
[Enum2] DECIMAL(20,0) NOT NULL,
[Enum2Nullable] DECIMAL(20,0),
PRIMARY KEY ([Id])
)
;
", sql);
}
//sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
}
IInsert<TableAllType> insert => g.msaccess.Insert<TableAllType>();
ISelect<TableAllType> select => g.msaccess.Select<TableAllType>();
[Fact]
public void CurdAllField()
{
var item = new TableAllType { };
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
var newitem = select.Where(a => a.Id == item.Id).ToOne();
var item2 = new TableAllType
{
Bool = true,
BoolNullable = true,
Byte = 255,
ByteNullable = 127,
Bytes = Encoding.UTF8.GetBytes("<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"),
DateTime = DateTime.Now,
DateTimeNullable = DateTime.Now.AddHours(-1),
Decimal = 99.99M,
DecimalNullable = 99.98M,
Double = 999.99,
DoubleNullable = 999.98,
Enum1 = TableAllTypeEnumType1.e5,
Enum1Nullable = TableAllTypeEnumType1.e3,
Enum2 = TableAllTypeEnumType2.f2,
Enum2Nullable = TableAllTypeEnumType2.f3,
Float = 19.99F,
FloatNullable = 19.98F,
Guid = Guid.NewGuid(),
GuidNullable = Guid.NewGuid(),
Int = int.MaxValue,
IntNullable = int.MinValue,
SByte = 100,
SByteNullable = 99,
Short = short.MaxValue,
ShortNullable = short.MinValue,
String = "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>string",
TimeSpan = TimeSpan.FromSeconds(999),
TimeSpanNullable = TimeSpan.FromSeconds(60),
UInt = uint.MaxValue,
UIntNullable = uint.MinValue,
ULong = ulong.MaxValue - 10000000,
ULongNullable = ulong.MinValue,
UShort = ushort.MaxValue,
UShortNullable = ushort.MinValue,
testFielLongNullable = long.MinValue
};
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
var items = select.ToList();
}
[Table(Name = "tb_alltype")]
class TableAllType
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
//public string id2 { get; set; } = "id2=10";
public bool Bool { get; set; }
public sbyte SByte { get; set; }
public short Short { get; set; }
public int Int { get; set; }
public long Long { get; set; }
public byte Byte { get; set; }
public ushort UShort { get; set; }
public uint UInt { get; set; }
public ulong ULong { get; set; }
public double Double { get; set; }
public float Float { get; set; }
public decimal Decimal { get; set; }
public TimeSpan TimeSpan { get; set; }
[Column(ServerTime = DateTimeKind.Local)]
public DateTime DateTime { get; set; }
[Column(ServerTime = DateTimeKind.Local)]
public DateTime DateTimeOffSet { get; set; }
public byte[] Bytes { get; set; }
public string String { get; set; }
public Guid Guid { get; set; }
public bool? BoolNullable { get; set; }
public sbyte? SByteNullable { get; set; }
public short? ShortNullable { get; set; }
public int? IntNullable { get; set; }
public long? testFielLongNullable { get; set; }
public byte? ByteNullable { get; set; }
public ushort? UShortNullable { get; set; }
public uint? UIntNullable { get; set; }
public ulong? ULongNullable { get; set; }
public double? DoubleNullable { get; set; }
public float? FloatNullable { get; set; }
public decimal? DecimalNullable { get; set; }
public TimeSpan? TimeSpanNullable { get; set; }
[Column(ServerTime = DateTimeKind.Local)]
public DateTime? DateTimeNullable { get; set; }
[Column(ServerTime = DateTimeKind.Local)]
public DateTime? DateTimeOffSetNullable { get; set; }
public Guid? GuidNullable { get; set; }
public TableAllTypeEnumType1 Enum1 { get; set; }
public TableAllTypeEnumType1? Enum1Nullable { get; set; }
public TableAllTypeEnumType2 Enum2 { get; set; }
public TableAllTypeEnumType2? Enum2Nullable { get; set; }
}
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
}
}

View File

@ -0,0 +1,169 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccessExpression
{
public class ConvertTest
{
ISelect<Topic> select => g.msaccess.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 TypeGuid { 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 : 0) > 0).ToList());
data.Add(select.Where(a => (bool.Parse(a.Clicks.ToString()) ? 1 : 0) > 0).ToList());
}
[Fact]
public void ToByte()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToByte(a.Clicks % 255) > 0).ToList());
data.Add(select.Where(a => byte.Parse((a.Clicks % 255).ToString()) > 0).ToList());
}
[Fact]
public void ToChar()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList());
data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList());
}
[Fact]
public void ToDateTime()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
data.Add(select.Where(a => DateTime.Parse(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());
data.Add(select.Where(a => decimal.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToDouble()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
data.Add(select.Where(a => double.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToInt16()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToInt32()
{
var data = new List<object>();
data.Add(select.Where(a => (int)a.Clicks > 0).ToList());
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
data.Add(select.Where(a => int.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToInt64()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
data.Add(select.Where(a => long.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToSByte()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToSByte(a.Clicks % 128) > 0).ToList());
data.Add(select.Where(a => sbyte.Parse((a.Clicks % 128).ToString()) > 0).ToList());
}
[Fact]
public void ToSingle()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
data.Add(select.Where(a => float.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
data.Add(select.Where(a => a.Clicks.ToString().Equals("")).ToList());
}
[Fact]
public void ToUInt16()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToUInt32()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
data.Add(select.Where(a => uint.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void ToUInt64()
{
var data = new List<object>();
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
data.Add(select.Where(a => ulong.Parse(a.Clicks.ToString()) > 0).ToList());
}
[Fact]
public void Guid_Parse()
{
var data = new List<object>();
data.Add(select.Where(a => Guid.Parse(Guid.Empty.ToString()) == Guid.Empty).ToList());
}
[Fact]
public void Guid_NewGuid()
{
var data = new List<object>();
//data.Add(select.OrderBy(a => Guid.NewGuid()).Limit(10).ToList());
}
[Fact]
public void Random()
{
var data = new List<object>();
data.Add(select.Where(a => new Random().Next() > a.Clicks).Limit(10).ToList());
data.Add(select.Where(a => new Random().NextDouble() > a.Clicks).Limit(10).ToList());
}
}
}

View File

@ -0,0 +1,706 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccessExpression
{
public class DateTimeTest
{
ISelect<Topic> select => g.msaccess.Select<Topic>();
[Table(Name = "tb_topic111333")]
class Topic
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int Clicks { get; set; }
public int TypeGuid { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
[Table(Name = "TestTypeInfo333")]
class TestTypeInfo
{
[Column(IsIdentity = true)]
public int Guid { get; set; }
public int ParentId { get; set; }
public TestTypeParentInfo Parent { get; set; }
public string Name { get; set; }
public DateTime Time { get; set; }
}
[Table(Name = "TestTypeParentInfo23123")]
class TestTypeParentInfo
{
public int Id { get; set; }
public string Name { get; set; }
public List<TestTypeInfo> Types { get; set; }
public DateTime Time2 { get; set; }
}
[Fact]
public void Now()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void UtcNow()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void MinValue()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void MaxValue()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Date()
{
var data = new List<object>();
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.Parent.Time2.Date > DateTime.Now.Date).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (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.Type.Time.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.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (((timestampdiff(microsecond, cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (((timestampdiff(microsecond, cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0)
}
[Fact]
public void TimeOfDay()
{
var data = new List<object>();
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.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((timestampdiff(microsecond, 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((timestampdiff(microsecond, 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]
public void DayOfWeek()
{
var data = new List<object>();
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.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((dayofweek(a__Type.`Time`) - 1) > (dayofweek(now()) - 1));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((dayofweek(a__Type__Parent.`Time2`) - 1) > (dayofweek(now()) - 1))
}
[Fact]
public void Day()
{
var data = new List<object>();
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.Parent.Time2.Day > DateTime.Now.Day).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (dayofmonth(a__Type.`Time`) > dayofmonth(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (dayofmonth(a__Type__Parent.`Time2`) > dayofmonth(now()))
}
[Fact]
public void DayOfYear()
{
var data = new List<object>();
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.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (dayofyear(a__Type.`Time`) > dayofyear(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (dayofyear(a__Type__Parent.`Time2`) > dayofyear(now()))
}
[Fact]
public void Month()
{
var data = new List<object>();
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.Parent.Time2.Month > DateTime.Now.Month).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (month(a__Type.`Time`) > month(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (month(a__Type__Parent.`Time2`) > month(now()))
}
[Fact]
public void Year()
{
var data = new List<object>();
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.Parent.Time2.Year > DateTime.Now.Year).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (year(a__Type.`Time`) > year(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (year(a__Type__Parent.`Time2`) > year(now()))
}
[Fact]
public void Hour()
{
var data = new List<object>();
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.Parent.Time2.Hour > DateTime.Now.Hour).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (hour(a__Type.`Time`) > hour(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (hour(a__Type__Parent.`Time2`) > hour(now()))
}
[Fact]
public void Minute()
{
var data = new List<object>();
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.Parent.Time2.Minute > DateTime.Now.Minute).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (minute(a__Type.`Time`) > minute(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (minute(a__Type__Parent.`Time2`) > minute(now()))
}
[Fact]
public void Second()
{
var data = new List<object>();
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.Parent.Time2.Second > DateTime.Now.Second).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (second(a__Type.`Time`) > second(now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (second(a__Type__Parent.`Time2`) > second(now()))
}
[Fact]
public void Millisecond()
{
var data = new List<object>();
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.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (floor(microsecond(a__Type.`Time`) / 1000) > floor(microsecond(now()) / 1000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (floor(microsecond(a__Type__Parent.`Time2`) / 1000) > floor(microsecond(now()) / 1000))
}
[Fact]
public void Ticks()
{
var data = new List<object>();
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.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type.`Time`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type__Parent.`Time2`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000))
}
[Fact]
public void Add()
{
var data = new List<object>();
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.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > now())
}
[Fact]
public void AddDays()
{
var data = new List<object>();
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.Parent.Time2.AddDays(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) day) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) day) > now())
}
[Fact]
public void AddHours()
{
var data = new List<object>();
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.Parent.Time2.AddHours(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) hour) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) hour) > now())
}
[Fact]
public void AddMilliseconds()
{
var data = new List<object>();
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.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) * 1000 microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) * 1000 microsecond) > now())
}
[Fact]
public void AddMinutes()
{
var data = new List<object>();
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.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) minute) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) minute) > now())
}
[Fact]
public void AddMonths()
{
var data = new List<object>();
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.Parent.Time2.AddMonths(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) month) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) month) > now())
}
[Fact]
public void AddSeconds()
{
var data = new List<object>();
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.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) second) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) second) > now())
}
[Fact]
public void AddTicks()
{
var data = new List<object>();
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.Parent.Time2.AddTicks(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) / 10 microsecond) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) / 10 microsecond) > now())
}
[Fact]
public void AddYears()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (date_add(a__Type.`Time`, interval (1) year) > now());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) year) > now())
}
[Fact]
public void Subtract()
{
var data = new List<object>();
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.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//WHERE (((strftime('%s',a."CreateTime")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//WHERE (((strftime('%s',a__Type."Time")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
//WHERE (((strftime('%s',a__Type__Parent."Time2")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
data.Add(select.Where(a => a.CreateTime.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());
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//WHERE (datetime(a."CreateTime",(-((1)*86400))||' seconds') > a."CreateTime")
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//WHERE (datetime(a__Type."Time",(-((1)*86400))||' seconds') > a."CreateTime")
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
//WHERE (datetime(a__Type__Parent."Time2",(-((1)*86400))||' seconds') > a."CreateTime")
}
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬSubtract()
{
var data = new List<object>();
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//WHERE (((strftime('%s',a."CreateTime")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//WHERE (((strftime('%s',a__Type."Time")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
//WHERE (((strftime('%s',a__Type__Parent."Time2")-strftime('%s',datetime(current_timestamp,'localtime')))) > 0)
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
//SELECT a."Id", a."Clicks", a."TypeGuid", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//WHERE (datetime(a."CreateTime",(-((1)*86400))||' seconds') > a."CreateTime")
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//WHERE (datetime(a__Type."Time",(-((1)*86400))||' seconds') > a."CreateTime")
//SELECT a."Id", a."Clicks", a."TypeGuid", a__Type."Guid", a__Type."ParentId", a__Type."Name", a__Type."Time", a."Title", a."CreateTime"
//FROM "tb_topic111333" a
//LEFT JOIN "TestTypeInfo333" a__Type ON a__Type."Guid" = a."TypeGuid"
//LEFT JOIN "TestTypeParentInfo23123" a__Type__Parent ON a__Type__Parent."Id" = a__Type."ParentId"
//WHERE (datetime(a__Type__Parent."Time2",(-((1)*86400))||' seconds') > a."CreateTime")
}
[Fact]
public void this_Equals()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_add(a__Type.`Time`, interval (1) year) = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
}
[Fact]
public void DateTime_Compare()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE (((a.`CreateTime`) - (now())) = 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (((date_add(a__Type.`Time`, interval (1) year)) - (now())) = 0);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (((date_add(a__Type__Parent.`Time2`, interval (1) year)) - (now())) = 0)
}
[Fact]
public void DateTime_DaysInMonth()
{
var data = new List<object>();
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.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (dayofmonth(last_day(concat(year(a__Type.`Time`), month(a__Type.`Time`), '-01'))) > 30);
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (dayofmonth(last_day(concat(year(a__Type__Parent.`Time2`), month(a__Type__Parent.`Time2`), '-01'))) > 30)
}
[Fact]
public void DateTime_Equals()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1), DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_add(a__Type.`Time`, interval (1) year) = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
}
[Fact]
public void DateTime_IsLeapYear()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1).Year)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (((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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (((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]
public void DateTime_Parse()
{
var data = new List<object>();
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.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE (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.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE (cast(date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now())
}
}
}

View File

@ -0,0 +1,156 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccessExpression
{
public class MathTest
{
ISelect<Topic> select => g.msaccess.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 TypeGuid { 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 PI()
{
var data = new List<object>();
data.Add(select.Where(a => Math.PI + a.Clicks > 0).ToList());
}
[Fact]
public void Abs()
{
var data = new List<object>();
data.Add(select.Where(a => Math.Abs(-a.Clicks) > 0).ToList());
}
[Fact]
public void Sign()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Sign(-a.Clicks) > 0).ToList());
}
[Fact]
public void Floor()
{
var data = new List<object>();
data.Add(select.Where(a => Math.Floor(a.Clicks + 0.5) == a.Clicks).ToList());
}
[Fact]
public void Ceiling()
{
var data = new List<object>();
data.Add(select.Where(a => Math.Ceiling(a.Clicks + 0.5) == a.Clicks + 1).ToList());
}
[Fact]
public void Round()
{
var data = new List<object>();
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5) == a.Clicks).ToList());
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5, 1) > a.Clicks).ToList());
}
[Fact]
public void Exp()
{
var data = new List<object>();
data.Add(select.Where(a => Math.Exp(1) == a.Clicks + 1).ToList());
}
[Fact]
public void Log()
{
var data = new List<object>();
data.Add(select.Where(a => Math.Log(a.Clicks + 0.5) == a.Clicks + 1).ToList());
}
[Fact]
public void Log10()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Log10(a.Clicks + 0.5) == a.Clicks + 1).ToList());
}
[Fact]
public void Pow()
{
// var data = new List<object>();
// data.Add(select.Where(a => Math.Pow(2, a.Clicks % 5) == a.Clicks + 1).ToList());
}
[Fact]
public void Sqrt()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Sqrt(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Cos()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Cos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Sin()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Sin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Tan()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Tan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Acos()
{
var data = new List<object>();
//data.Add(select.Where(a => Math.Acos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Asin()
{
var data = new List<object>();
//data.Add(select.Where(a => Math.Asin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Atan()
{
//var data = new List<object>();
//data.Add(select.Where(a => Math.Atan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
}
[Fact]
public void Atan2()
{
var data = new List<object>();
//data.Add(select.Where(a => Math.Atan2(2, a.Clicks) == a.Clicks + 1).ToList());
}
[Fact]
public void Truncate()
{
var data = new List<object>();
//data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList());
}
}
}

View File

@ -0,0 +1,164 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccessExpression
{
public class OtherTest
{
ISelect<TableAllType> select => g.msaccess.Select<TableAllType>();
public OtherTest()
{
}
[Fact]
public void Div()
{
var t1 = select.Where(a => a.Int / 3 > 3).Limit(10).ToList();
var t2 = select.Where(a => a.Long / 3 > 3).Limit(10).ToList();
var t3 = select.Where(a => a.Short / 3 > 3).Limit(10).ToList();
var t4 = select.Where(a => a.Int / 3.0 > 3).Limit(10).ToList();
var t5 = select.Where(a => a.Long / 3.0 > 3).Limit(10).ToList();
var t6 = select.Where(a => a.Short / 3.0 > 3).Limit(10).ToList();
var t7 = select.Where(a => a.Double / 3 > 3).Limit(10).ToList();
var t8 = select.Where(a => a.Decimal / 3 > 3).Limit(10).ToList();
var t9 = select.Where(a => a.Float / 3 > 3).Limit(10).ToList();
}
[Fact]
public void Boolean()
{
var t1 = select.Where(a => a.Bool == true).ToList();
var t2 = select.Where(a => a.Bool != true).ToList();
var t3 = select.Where(a => a.Bool == false).ToList();
var t4 = select.Where(a => !a.Bool).ToList();
var t5 = select.Where(a => a.Bool).ToList();
var t51 = select.WhereCascade(a => a.Bool).Limit(10).ToList();
var t11 = select.Where(a => a.BoolNullable == true).ToList();
var t22 = select.Where(a => a.BoolNullable != true).ToList();
var t33 = select.Where(a => a.BoolNullable == false).ToList();
var t44 = select.Where(a => !a.BoolNullable.Value).ToList();
var t55 = select.Where(a => a.BoolNullable.Value).ToList();
var t111 = select.Where(a => a.Bool == true && a.Id > 0).ToList();
var t222 = select.Where(a => a.Bool != true && a.Id > 0).ToList();
var t333 = select.Where(a => a.Bool == false && a.Id > 0).ToList();
var t444 = select.Where(a => !a.Bool && a.Id > 0).ToList();
var t555 = select.Where(a => a.Bool && a.Id > 0).ToList();
var t1111 = select.Where(a => a.BoolNullable == true && a.Id > 0).ToList();
var t2222 = select.Where(a => a.BoolNullable != true && a.Id > 0).ToList();
var t3333 = select.Where(a => a.BoolNullable == false && a.Id > 0).ToList();
var t4444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0).ToList();
var t5555 = select.Where(a => a.BoolNullable.Value && a.Id > 0).ToList();
var t11111 = select.Where(a => a.Bool == true && a.Id > 0 && a.Bool == true).ToList();
var t22222 = select.Where(a => a.Bool != true && a.Id > 0 && a.Bool != true).ToList();
var t33333 = select.Where(a => a.Bool == false && a.Id > 0 && a.Bool == false).ToList();
var t44444 = select.Where(a => !a.Bool && a.Id > 0 && !a.Bool).ToList();
var t55555 = select.Where(a => a.Bool && a.Id > 0 && a.Bool).ToList();
var t111111 = select.Where(a => a.BoolNullable == true && a.Id > 0 && a.BoolNullable == true).ToList();
var t222222 = select.Where(a => a.BoolNullable != true && a.Id > 0 && a.BoolNullable != true).ToList();
var t333333 = select.Where(a => a.BoolNullable == false && a.Id > 0 && a.BoolNullable == false).ToList();
var t444444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0 && !a.BoolNullable.Value).ToList();
var t555555 = select.Where(a => a.BoolNullable.Value && a.Id > 0 && a.BoolNullable.Value).ToList();
}
[Fact]
public void Array()
{
IEnumerable<int> testlinqlist = new List<int>(new[] { 1, 2, 3 });
var testlinq = select.Where(a => testlinqlist.Contains(a.Int)).ToList();
//in not in
var sql111 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int)).ToList();
var sql112 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int) == false).ToList();
var sql113 = select.Where(a => !new[] { 1, 2, 3 }.Contains(a.Int)).ToList();
var inarray = new[] { 1, 2, 3 };
var sql1111 = select.Where(a => inarray.Contains(a.Int)).ToList();
var sql1122 = select.Where(a => inarray.Contains(a.Int) == false).ToList();
var sql1133 = select.Where(a => !inarray.Contains(a.Int)).ToList();
//in not in
var sql11111 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.Int)).ToList();
var sql11222 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.Int) == false).ToList();
var sql11333 = select.Where(a => !new List<int>() { 1, 2, 3 }.Contains(a.Int)).ToList();
var sql11111a = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.Int)).ToList();
var sql11222b = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.Int) == false).ToList();
var sql11333c = select.Where(a => !new List<int>(new[] { 1, 2, 3 }).Contains(a.Int)).ToList();
var inarray2 = new List<int>() { 1, 2, 3 };
var sql111111 = select.Where(a => inarray.Contains(a.Int)).ToList();
var sql112222 = select.Where(a => inarray.Contains(a.Int) == false).ToList();
var sql113333 = select.Where(a => !inarray.Contains(a.Int)).ToList();
var inarray2n = Enumerable.Range(1, 3333).ToArray();
var sql1111111 = select.Where(a => inarray2n.Contains(a.Int)).ToList();
var sql1122222 = select.Where(a => inarray2n.Contains(a.Int) == false).ToList();
var sql1133333 = select.Where(a => !inarray2n.Contains(a.Int)).ToList();
}
[Table(Name = "tb_alltype")]
class TableAllType
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public string id2 { get; set; } = "id2=10";
public bool Bool { get; set; }
public sbyte SByte { get; set; }
public short Short { get; set; }
public int Int { get; set; }
public long Long { get; set; }
public byte Byte { get; set; }
public ushort UShort { get; set; }
public uint UInt { get; set; }
public ulong ULong { get; set; }
public double Double { get; set; }
public float Float { get; set; }
public decimal Decimal { get; set; }
public TimeSpan TimeSpan { get; set; }
public DateTime DateTime { get; set; }
public DateTime DateTimeOffSet { get; set; }
public byte[] Bytes { get; set; }
public string String { get; set; }
public Guid Guid { get; set; }
public bool? BoolNullable { get; set; }
public sbyte? SByteNullable { get; set; }
public short? ShortNullable { get; set; }
public int? IntNullable { get; set; }
public long? testFielLongNullable { get; set; }
public byte? ByteNullable { get; set; }
public ushort? UShortNullable { get; set; }
public uint? UIntNullable { get; set; }
public ulong? ULongNullable { get; set; }
public double? DoubleNullable { get; set; }
public float? FloatNullable { get; set; }
public decimal? DecimalNullable { get; set; }
public TimeSpan? TimeSpanNullable { get; set; }
public DateTime? DateTimeNullable { get; set; }
public DateTime? DateTimeOffSetNullable { get; set; }
public Guid? GuidNullable { get; set; }
public TableAllTypeEnumType1 Enum1 { get; set; }
public TableAllTypeEnumType1? Enum1Nullable { get; set; }
public TableAllTypeEnumType2 Enum2 { get; set; }
public TableAllTypeEnumType2? Enum2Nullable { get; set; }
}
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
}
}

View File

@ -0,0 +1,728 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccessExpression
{
public class StringTest
{
ISelect<Topic> select => g.msaccess.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 TypeGuid { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
class TestTypeInfo
{
[Column(IsIdentity = true)]
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; }
}
class TestEqualsGuid
{
public Guid id { get; set; }
}
[Fact]
public void Equals__()
{
var list = new List<object>();
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
list.Add(g.msaccess.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
}
[Fact]
public void Empty()
{
var data = new List<object>();
data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (ifnull(a.`Title`, '') = '')
}
[Fact]
public void StartsWith()
{
var list = new List<object>();
list.Add(select.Where(a => a.Title.StartsWith("aaa")).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.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE '%aaa')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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(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.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void EndsWith()
{
var list = new List<object>();
list.Add(select.Where(a => a.Title.EndsWith("aaa")).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.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE 'aaa%')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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(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.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void Contains()
{
var list = new List<object>();
list.Add(select.Where(a => a.Title.Contains("aaa")).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.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE((a.`Title`) LIKE '%aaa%')
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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(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.Type.Name)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void ToLower()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.ToLower() == "aaa").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.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE(lower(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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() == 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.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void ToUpper()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.ToUpper() == "aaa").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.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (upper(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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() == 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.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void Substring()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.Substring(0) == "aaa").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.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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(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(1, 2) == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void Length()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.Length == 0).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.Type.Name.Length).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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 == 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());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void IndexOf()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.IndexOf("aaa") == -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.Type.Name.Length + 1).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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", 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.Type.Name.Length + 1).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void PadLeft()
{
//var data = new List<object>();
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").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.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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') == 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.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void PadRight()
{
//var data = new List<object>();
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").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.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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') == 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.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void Trim()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.Trim() == "aaa").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', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (trim(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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('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', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void TrimStart()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.TrimStart() == "aaa").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', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (ltrim(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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('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', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void TrimEnd()
{
var data = new List<object>();
data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").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', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (rtrim(a.`Title`) = 'aaa');
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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('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', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void Replace()
{
//System.Data.OleDb.OleDbException : <20><><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD> 'replace' <20><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>
//var data = new List<object>();
//data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").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(a.Type.Name, "a") == a.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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").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(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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]
public void CompareTo()
{
var data = new List<object>();
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 + a.Type.Name) == 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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(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.Type.Name) == 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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.`TypeGuid` 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)
}
[Fact]
public void string_IsNullOrEmpty()
{
var data = new List<object>();
data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList());
//data.Add(select.Where(a => string.IsNullOrEmpty(a.Title) == false).ToList());
data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList());
}
[Fact]
public void string_IsNullOrWhiteSpace()
{
var data = new List<object>();
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList());
//data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title) == false).ToList());
data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList());
}
}
}

View File

@ -0,0 +1,293 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.MsAccessExpression
{
public class TimeSpanTest
{
ISelect<Topic> select => g.msaccess.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 TypeGuid { 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 Zero()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void MinValue()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void MaxValue()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Days()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Hours()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Milliseconds()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Minutes()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Seconds()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Ticks()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TotalDays()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TotalHours()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TotalMilliseconds()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TotalMinutes()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TotalSeconds()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Add()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void Subtract()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void CompareTo()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void this_Equals()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_Compare()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_Equals()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_FromDays()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_FromHours()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_FromMilliseconds()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_FromMinutes()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_FromSeconds()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_FromTicks()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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]
public void TimeSpan_Parse()
{
var data = new List<object>();
data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` 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

@ -1059,12 +1059,12 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2
FROM (SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
FROM `tb_topic_1` a) ftb
UNION ALL
SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
FROM `tb_topic_2` a) ftb) a
FROM `tb_topic_1` a) ftb
UNION ALL
SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
FROM `tb_topic_2` a) ftb) a
limit 0,20", select
.AsTable((type, old) => type == typeof(Topic) ? $"({sqlsss})" : null)
.Page(1, 20)
@ -1073,6 +1073,83 @@ limit 0,20", select
a.Id,
a.Clicks
}));
var sqltmp12 = g.mysql.Select<WF_Task>()
.Where(t => t.IsFinished && (t.AuditorId == "1" || t.AuditorId == "1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3"))
.GroupBy(t => new { t.ProcessId, t.NodeId, t.NodeName })
.ToSql(t => new WF_TaskGroupBy
{
TaskId = t.Max(t.Value.Id),
TaskType = t.Max(t.Value.Type),
ProcessId = t.Key.ProcessId,
NodeId = t.Key.NodeId,
NodeName = t.Key.NodeName
}, FieldAliasOptions.AsProperty);
var groupsql12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => type == typeof(WF_TaskGroupBy) ? $"( {sqltmp12} )" : null)
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToSql((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
LEFT JOIN `WF_ProcessInstance` b ON b.`Id` = a.`ProcessId`
WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql12);
var grouplist12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => $"( {sqltmp12} )")
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToList((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
}
[Table(DisableSyncStructure = true)]
class WF_TaskGroupBy
{
public int TaskId { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
}
class WF_Task
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int Type { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
public string AuditorId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
}
class WF_ProcessInstance
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
public bool EnabledMark { get; set; }
}
public class TestInclude_OneToManyModel1

View File

@ -91,4 +91,18 @@ public class g
)
.Build());
public static IFreeSql sqlite => sqliteLazy.Value;
static Lazy<IFreeSql> msaccessLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MsAccess, @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:/accdb/2003.mdb;max pool size=5")
.UseConnectionString(FreeSql.DataType.MsAccess, @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:/accdb/2007.accdb;max pool size=5")
.UseAutoSyncStructure(true)
//.UseGenerateCommandParameterWithLambda(true)
.UseLazyLoading(true)
.UseMonitorCommand(
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象在执行前
//, (cmd, traceLog) => Console.WriteLine(traceLog)
)
.Build());
public static IFreeSql msaccess => msaccessLazy.Value;
}