mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 修复 Ado.Query 查询字段重复时报错;#162 #165 #161 - 增加 FreeSql.Provider.MsAccess 支持 Access 数据库操作,已通过 2003/2007 版本测试;
This commit is contained in:
parent
d5ed1c8a30
commit
a92c279c72
@ -28,7 +28,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<Version>0.12.21</Version>
|
<Version>0.12.21</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql is the ORM in .NetCore, .NetFramework, And Xamarin. It supports Mysql, Postgresql, SqlServer, Oracle, Sqlite, And Odbc. 达梦</Description>
|
<Description>FreeSql is the ORM in .NetCore, .NetFramework, And Xamarin. It supports Mysql, Postgresql, SqlServer, Oracle, Sqlite, Odbc, 达梦, And Access</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql.DbContext</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql.DbContext</PackageProjectUrl>
|
||||||
<PackageTags>FreeSql ORM DbContext</PackageTags>
|
<PackageTags>FreeSql ORM DbContext</PackageTags>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
|
@ -110,6 +110,13 @@
|
|||||||
清空状态数据
|
清空状态数据
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||||
|
<summary>
|
||||||
|
根据 lambda 条件删除数据
|
||||||
|
</summary>
|
||||||
|
<param name="predicate"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||||
<summary>
|
<summary>
|
||||||
添加
|
添加
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||||
<Version>0.12.21</Version>
|
<Version>0.12.21</Version>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite/达梦, and read/write separation、and split table.</Description>
|
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite/达梦/Access, and read/write separation、and split table.</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
||||||
<PackageTags>FreeSql ORM Repository</PackageTags>
|
<PackageTags>FreeSql ORM Repository</PackageTags>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
@ -1014,6 +1014,83 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
|||||||
a.Id,
|
a.Id,
|
||||||
a.Clicks
|
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
|
public class TestInclude_OneToManyModel1
|
||||||
|
@ -1025,6 +1025,83 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
|||||||
a.Id,
|
a.Id,
|
||||||
a.Clicks
|
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
|
public class TestInclude_OneToManyModel1
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
|
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
|
||||||
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
||||||
<ProjectReference Include="..\..\FreeSql\FreeSql.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.MySql\FreeSql.Provider.MySql.csproj" />
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
141
FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessInsertTest.cs
Normal file
141
FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessInsertTest.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1414
FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessSelectTest.cs
Normal file
1414
FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessSelectTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
141
FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessUpdateTest.cs
Normal file
141
FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessUpdateTest.cs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1571
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/BoolNullableTest.cs
Normal file
1571
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/BoolNullableTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
1105
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/BoolTest.cs
Normal file
1105
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/BoolTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
261
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/EnumTest.cs
Normal file
261
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/EnumTest.cs
Normal 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 { 中国人, abc, 香港 }
|
||||||
|
[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.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, 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.香港;
|
||||||
|
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||||
|
|
||||||
|
item.enum_to_string = ToStringMapEnum.中国人;
|
||||||
|
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, 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.香港).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, 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.中国人).ExecuteAffrows());
|
||||||
|
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).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.中国人 };
|
||||||
|
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||||
|
|
||||||
|
//update all
|
||||||
|
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||||
|
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, 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.香港).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.中国人).ExecuteAffrows());
|
||||||
|
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).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.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, 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.香港;
|
||||||
|
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||||
|
|
||||||
|
item.enum_to_int = ToStringMapEnum.中国人;
|
||||||
|
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, 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.香港).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, 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.中国人).ExecuteAffrows());
|
||||||
|
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).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.中国人 };
|
||||||
|
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_int);
|
||||||
|
|
||||||
|
//update all
|
||||||
|
item.enumnullable_to_int = ToStringMapEnum.香港;
|
||||||
|
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, 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.香港).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.中国人).ExecuteAffrows());
|
||||||
|
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
570
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/ToStringTest.cs
Normal file
570
FreeSql.Tests/FreeSql.Tests/MsAccess/MapType/ToStringTest.cs
Normal 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 { 中国人, abc, 香港 }
|
||||||
|
[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.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, 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.香港;
|
||||||
|
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||||
|
|
||||||
|
item.enum_to_string = ToStringMapEnum.中国人;
|
||||||
|
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, 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.香港).ExecuteAffrows());
|
||||||
|
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, 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.中国人).ExecuteAffrows());
|
||||||
|
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).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.中国人 };
|
||||||
|
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||||
|
|
||||||
|
//update all
|
||||||
|
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||||
|
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||||
|
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||||
|
Assert.Equal(ToStringMapEnum.香港, 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.香港).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.中国人).ExecuteAffrows());
|
||||||
|
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
FreeSql.Tests/FreeSql.Tests/MsAccess/MsAccessAopTest.cs
Normal file
40
FreeSql.Tests/FreeSql.Tests/MsAccess/MsAccessAopTest.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
307
FreeSql.Tests/FreeSql.Tests/MsAccess/MsAccessCodeFirstTest.cs
Normal file
307
FreeSql.Tests/FreeSql.Tests/MsAccess/MsAccessCodeFirstTest.cs
Normal 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 中文表_字段()
|
||||||
|
{
|
||||||
|
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
|
g.msaccess.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
|
var item = new 测试中文表
|
||||||
|
{
|
||||||
|
标题 = "测试标题",
|
||||||
|
创建时间 = DateTime.Now
|
||||||
|
};
|
||||||
|
Assert.Equal(1, g.msaccess.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
|
var item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
|
Assert.NotNull(item2);
|
||||||
|
Assert.Equal(item.编号, item2.编号);
|
||||||
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
}
|
||||||
|
class 测试中文表
|
||||||
|
{
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime 创建时间 { 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
//秀一波 FreeSql.Repository 扩展包,dotnet add package FreeSql.Repository
|
||||||
|
var topicRepository = g.msaccess.GetGuidRepository<Topic>();
|
||||||
|
var commentRepository = g.msaccess.GetGuidRepository<Comment>();
|
||||||
|
|
||||||
|
//添加测试文章
|
||||||
|
var topic = topicRepository.Insert(new Topic
|
||||||
|
{
|
||||||
|
Title = "文章标题1",
|
||||||
|
Content = "文章内容1",
|
||||||
|
CreateTime = DateTime.Now
|
||||||
|
});
|
||||||
|
|
||||||
|
//添加10条测试评论
|
||||||
|
var comments = Enumerable.Range(0, 10).Select(a => new Comment
|
||||||
|
{
|
||||||
|
TopicId = topic.Id,
|
||||||
|
Nickname = $"昵称{a}",
|
||||||
|
Content = $"评论内容{a}",
|
||||||
|
CreateTime = DateTime.Now
|
||||||
|
}).ToArray();
|
||||||
|
var affrows = commentRepository.Insert(comments);
|
||||||
|
|
||||||
|
var find = commentRepository.Select.Where(a => a.Topic.Title == "文章标题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("我是中国人"),
|
||||||
|
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 = "我是中国人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 }
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬ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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 }
|
||||||
|
}
|
||||||
|
}
|
@ -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 : ±í´ïʽÖÐ 'replace' º¯Êý䶨Òå¡£
|
||||||
|
//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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1059,12 +1059,12 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
|||||||
|
|
||||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2
|
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2
|
||||||
FROM (SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
|
FROM (SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
|
||||||
FROM `tb_topic_1` a) ftb
|
FROM `tb_topic_1` a) ftb
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
|
SELECT * from (SELECT a.`Id` Id, a.`Clicks` Clicks
|
||||||
FROM `tb_topic_2` a) ftb) a
|
FROM `tb_topic_2` a) ftb) a
|
||||||
limit 0,20", select
|
limit 0,20", select
|
||||||
.AsTable((type, old) => type == typeof(Topic) ? $"({sqlsss})" : null)
|
.AsTable((type, old) => type == typeof(Topic) ? $"({sqlsss})" : null)
|
||||||
.Page(1, 20)
|
.Page(1, 20)
|
||||||
@ -1073,6 +1073,83 @@ limit 0,20", select
|
|||||||
a.Id,
|
a.Id,
|
||||||
a.Clicks
|
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
|
public class TestInclude_OneToManyModel1
|
||||||
|
@ -91,4 +91,18 @@ public class g
|
|||||||
)
|
)
|
||||||
.Build());
|
.Build());
|
||||||
public static IFreeSql sqlite => sqliteLazy.Value;
|
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;
|
||||||
}
|
}
|
||||||
|
15
FreeSql.sln
15
FreeSql.sln
@ -70,6 +70,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Generator", "Extens
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "FreeSql.Tests.VB", "FreeSql.Tests.VB\FreeSql.Tests.VB.vbproj", "{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}"
|
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "FreeSql.Tests.VB", "FreeSql.Tests.VB\FreeSql.Tests.VB.vbproj", "{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.MsAccess", "Providers\FreeSql.Provider.MsAccess\FreeSql.Provider.MsAccess.csproj", "{B397A761-F646-41CF-A160-AB6C05DAF2FB}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -416,6 +418,18 @@ Global
|
|||||||
{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}.Release|x64.Build.0 = Release|Any CPU
|
{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}.Release|x86.ActiveCfg = Release|Any CPU
|
{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}.Release|x86.Build.0 = Release|Any CPU
|
{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -440,6 +454,7 @@ Global
|
|||||||
{C57444BA-8BF7-4790-A864-7F237123219B} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
{C57444BA-8BF7-4790-A864-7F237123219B} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
{1674BCE3-EEB4-4003-A2A7-06F51EFAEA23} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
{1674BCE3-EEB4-4003-A2A7-06F51EFAEA23} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||||
{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
|
{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
|
||||||
|
{B397A761-F646-41CF-A160-AB6C05DAF2FB} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||||
|
@ -22,8 +22,13 @@ namespace FreeSql
|
|||||||
Odbc,
|
Odbc,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 国产数据库达梦
|
/// 武汉达梦数据库有限公司
|
||||||
/// </summary>
|
/// </summary>
|
||||||
OdbcDameng,
|
OdbcDameng,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Microsoft Office Access 是由微软发布的关联式数据库管理系统
|
||||||
|
/// </summary>
|
||||||
|
MsAccess,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<Version>0.12.21</Version>
|
<Version>0.12.21</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql is the ORM in .NetCore, .NetFramework, And Xamarin. It supports Mysql, Postgresql, SqlServer, Oracle, Sqlite, And Odbc. 达梦</Description>
|
<Description>FreeSql is the ORM in .NetCore, .NetFramework, And Xamarin. It supports Mysql, Postgresql, SqlServer, Oracle, Sqlite, Odbc, 达梦, And Access</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
@ -28,7 +28,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="SafeObjectPool" Version="2.2.0" />
|
<PackageReference Include="SafeObjectPool" Version="2.2.1" />
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -486,7 +486,12 @@
|
|||||||
</member>
|
</member>
|
||||||
<member name="F:FreeSql.DataType.OdbcDameng">
|
<member name="F:FreeSql.DataType.OdbcDameng">
|
||||||
<summary>
|
<summary>
|
||||||
国产数据库达梦
|
武汉达梦数据库有限公司
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="F:FreeSql.DataType.MsAccess">
|
||||||
|
<summary>
|
||||||
|
Microsoft Office Access 是由微软发布的关联式数据库管理系统
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
||||||
@ -1725,7 +1730,7 @@
|
|||||||
【linq to sql】专用方法,不建议直接使用
|
【linq to sql】专用方法,不建议直接使用
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.ISelectGrouping`2.ToSql``1(System.Linq.Expressions.Expression{System.Func{FreeSql.ISelectGroupingAggregate{`0,`1},``0}})">
|
<member name="M:FreeSql.ISelectGrouping`2.ToSql``1(System.Linq.Expressions.Expression{System.Func{FreeSql.ISelectGroupingAggregate{`0,`1},``0}},FreeSql.FieldAliasOptions)">
|
||||||
<summary>
|
<summary>
|
||||||
返回即将执行的SQL语句
|
返回即将执行的SQL语句
|
||||||
</summary>
|
</summary>
|
||||||
@ -2200,137 +2205,6 @@
|
|||||||
<param name="parms"></param>
|
<param name="parms"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
|
|
||||||
</summary>
|
|
||||||
<param name="readerHander"></param>
|
|
||||||
<param name="cmdType"></param>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询,ExecuteReaderAsync(dr => {}, "select * from user where age > @age", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
查询
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询,ExecuteArrayAsync("select * from user where age > @age", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
查询
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询,ExecuteDataSetAsync("select * from user where age > @age; select 2", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
查询
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询,ExecuteDataTableAsync("select * from user where age > @age", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
在【主库】执行
|
|
||||||
</summary>
|
|
||||||
<param name="cmdType"></param>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
在【主库】执行,ExecuteNonQueryAsync("delete from user where age > @age", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
在【主库】执行
|
|
||||||
</summary>
|
|
||||||
<param name="cmdType"></param>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
在【主库】执行,ExecuteScalarAsync("select 1 from user where age > @age", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new SqlParameter { ParameterName = "age", Value = 25 })
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T"></typeparam>
|
|
||||||
<param name="cmdType"></param>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T"></typeparam>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
|
||||||
<summary>
|
|
||||||
执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="cmdType"></param>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="cmdParms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.String,System.Object)">
|
|
||||||
<summary>
|
|
||||||
执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new { age = 25 })
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="cmdText"></param>
|
|
||||||
<param name="parms"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="P:FreeSql.IAop.ParseExpression">
|
<member name="P:FreeSql.IAop.ParseExpression">
|
||||||
<summary>
|
<summary>
|
||||||
可自定义解析表达式
|
可自定义解析表达式
|
||||||
|
@ -224,6 +224,11 @@ namespace FreeSql
|
|||||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Odbc.dll,可前往 nuget 下载");
|
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Odbc.dll,可前往 nuget 下载");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DataType.MsAccess:
|
||||||
|
type = Type.GetType("FreeSql.MsAccess.MsAccessProvider`1,FreeSql.Provider.MsAccess")?.MakeGenericType(typeof(TMark));
|
||||||
|
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.MsAccess.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
|
||||||
default: throw new Exception("未指定 UseConnectionString");
|
default: throw new Exception("未指定 UseConnectionString");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ namespace FreeSql
|
|||||||
/// <typeparam name="TReturn">返回类型</typeparam>
|
/// <typeparam name="TReturn">返回类型</typeparam>
|
||||||
/// <param name="select">选择列</param>
|
/// <param name="select">选择列</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
string ToSql<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select, FieldAliasOptions fieldAlias = FieldAliasOptions.AsIndex);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回即将执行的SQL语句
|
/// 返回即将执行的SQL语句
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -37,8 +37,8 @@ namespace FreeSql.Internal
|
|||||||
case ExpressionType.NegateChecked:
|
case ExpressionType.NegateChecked:
|
||||||
parent.DbField = $"-({ExpressionLambdaToSql(exp, getTSC())})";
|
parent.DbField = $"-({ExpressionLambdaToSql(exp, getTSC())})";
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(" ").Append(parent.CsName);
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
||||||
return false;
|
return false;
|
||||||
case ExpressionType.Convert: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand, getSelectGroupingMapString, whereCascadeExpression, isAllDtoMap);
|
case ExpressionType.Convert: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand, getSelectGroupingMapString, whereCascadeExpression, isAllDtoMap);
|
||||||
case ExpressionType.Constant:
|
case ExpressionType.Constant:
|
||||||
@ -56,8 +56,8 @@ namespace FreeSql.Internal
|
|||||||
else
|
else
|
||||||
parent.DbField = _common.FormatSql("{0}", constExp?.Value);
|
parent.DbField = _common.FormatSql("{0}", constExp?.Value);
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(" ").Append(parent.CsName);
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
||||||
return false;
|
return false;
|
||||||
case ExpressionType.Call:
|
case ExpressionType.Call:
|
||||||
var callExp = exp as MethodCallExpression;
|
var callExp = exp as MethodCallExpression;
|
||||||
@ -73,8 +73,8 @@ namespace FreeSql.Internal
|
|||||||
else
|
else
|
||||||
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(" ").Append(parent.CsName);
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
||||||
return false;
|
return false;
|
||||||
case ExpressionType.Parameter:
|
case ExpressionType.Parameter:
|
||||||
case ExpressionType.MemberAccess:
|
case ExpressionType.MemberAccess:
|
||||||
@ -97,7 +97,7 @@ namespace FreeSql.Internal
|
|||||||
MapType = map[idx].Column.Attribute.MapType
|
MapType = map[idx].Column.Attribute.MapType
|
||||||
};
|
};
|
||||||
field.Append(", ").Append(_common.QuoteReadColumn(child.MapType, child.DbField));
|
field.Append(", ").Append(_common.QuoteReadColumn(child.MapType, child.DbField));
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
parent.Childs.Add(child);
|
parent.Childs.Add(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,8 +106,8 @@ namespace FreeSql.Internal
|
|||||||
parent.CsType = exp.Type;
|
parent.CsType = exp.Type;
|
||||||
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(" ").Append(parent.CsName);
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
||||||
parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
|
parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
|
child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
|
||||||
field.Append(", ").Append(child.DbField);
|
field.Append(", ").Append(child.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
|
child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
|
||||||
field.Append(", ").Append(child.DbField);
|
field.Append(", ").Append(child.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -251,8 +251,8 @@ namespace FreeSql.Internal
|
|||||||
}
|
}
|
||||||
parent.DbField = $"({ExpressionLambdaToSql(exp, getTSC())})";
|
parent.DbField = $"({ExpressionLambdaToSql(exp, getTSC())})";
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(" as").Append(++index);
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(" ").Append(parent.CsName);
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public object ReadAnonymous(ReadAnonymousTypeInfo parent, DbDataReader dr, ref int index, bool notRead, ReadAnonymousDbValueRef dbValue)
|
public object ReadAnonymous(ReadAnonymousTypeInfo parent, DbDataReader dr, ref int index, bool notRead, ReadAnonymousDbValueRef dbValue)
|
||||||
@ -593,7 +593,7 @@ namespace FreeSql.Internal
|
|||||||
case ExpressionType.Constant: return formatSql((exp as ConstantExpression)?.Value, tsc.mapType, tsc.mapColumnTmp, null);
|
case ExpressionType.Constant: return formatSql((exp as ConstantExpression)?.Value, tsc.mapType, tsc.mapColumnTmp, null);
|
||||||
case ExpressionType.Conditional:
|
case ExpressionType.Conditional:
|
||||||
var condExp = exp as ConditionalExpression;
|
var condExp = exp as ConditionalExpression;
|
||||||
return $"case when {ExpressionLambdaToSql(condExp.Test, tsc)} then {ExpressionLambdaToSql(condExp.IfTrue, tsc)} else {ExpressionLambdaToSql(condExp.IfFalse, tsc)} end";
|
return _common.IIF(ExpressionLambdaToSql(condExp.Test, tsc), ExpressionLambdaToSql(condExp.IfTrue, tsc), ExpressionLambdaToSql(condExp.IfFalse, tsc));
|
||||||
case ExpressionType.Call:
|
case ExpressionType.Call:
|
||||||
tsc.mapType = null;
|
tsc.mapType = null;
|
||||||
var exp3 = exp as MethodCallExpression;
|
var exp3 = exp as MethodCallExpression;
|
||||||
|
@ -111,6 +111,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -153,6 +154,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -169,6 +171,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -219,6 +222,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -235,6 +239,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -251,6 +256,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -307,6 +313,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -323,6 +330,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -339,6 +347,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -355,6 +364,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -417,6 +427,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -433,6 +444,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -449,6 +461,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -465,6 +478,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -481,6 +495,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -655,7 +670,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (ret.Tables.Count <= result)
|
if (ret.Tables.Count <= result)
|
||||||
{
|
{
|
||||||
dt = ret.Tables.Add();
|
dt = ret.Tables.Add();
|
||||||
for (var a = 0; a < dr.FieldCount; a++) dt.Columns.Add(dr.GetName(a));
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
|
{
|
||||||
|
var name = dr.GetName(a);
|
||||||
|
if (dt.Columns.Contains(name)) name = $"{name}_{Guid.NewGuid().ToString("N").Substring(0, 4)}";
|
||||||
|
dt.Columns.Add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
object[] values = new object[dt.Columns.Count];
|
object[] values = new object[dt.Columns.Count];
|
||||||
dr.GetValues(values);
|
dr.GetValues(values);
|
||||||
@ -674,7 +694,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
ExecuteReader(connection, transaction, dr =>
|
ExecuteReader(connection, transaction, dr =>
|
||||||
{
|
{
|
||||||
if (ret.Columns.Count == 0)
|
if (ret.Columns.Count == 0)
|
||||||
for (var a = 0; a < dr.FieldCount; a++) ret.Columns.Add(dr.GetName(a));
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
|
{
|
||||||
|
var name = dr.GetName(a);
|
||||||
|
if (ret.Columns.Contains(name)) name = $"{name}_{Guid.NewGuid().ToString("N").Substring(0, 4)}";
|
||||||
|
ret.Columns.Add(name);
|
||||||
|
}
|
||||||
object[] values = new object[ret.Columns.Count];
|
object[] values = new object[ret.Columns.Count];
|
||||||
dr.GetValues(values);
|
dr.GetValues(values);
|
||||||
ret.Rows.Add(values);
|
ret.Rows.Add(values);
|
||||||
|
@ -35,6 +35,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -78,6 +79,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -94,6 +96,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -145,6 +148,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -161,6 +165,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -177,6 +182,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -234,6 +240,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -250,6 +257,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -266,6 +274,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -282,6 +291,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -345,6 +355,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -361,6 +372,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -377,6 +389,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -393,6 +406,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -409,6 +423,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
for (var a = 0; a < dr.FieldCount; a++)
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
{
|
{
|
||||||
var name = dr.GetName(a);
|
var name = dr.GetName(a);
|
||||||
|
if (dic.ContainsKey(name)) continue;
|
||||||
sbflag.Append(name).Append(":").Append(a).Append(",");
|
sbflag.Append(name).Append(":").Append(a).Append(",");
|
||||||
dic.Add(name, a);
|
dic.Add(name, a);
|
||||||
}
|
}
|
||||||
@ -585,7 +600,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (ret.Tables.Count <= result)
|
if (ret.Tables.Count <= result)
|
||||||
{
|
{
|
||||||
dt = ret.Tables.Add();
|
dt = ret.Tables.Add();
|
||||||
for (var a = 0; a < dr.FieldCount; a++) dt.Columns.Add(dr.GetName(a));
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
|
{
|
||||||
|
var name = dr.GetName(a);
|
||||||
|
if (dt.Columns.Contains(name)) name = $"{name}_{Guid.NewGuid().ToString("N").Substring(0, 4)}";
|
||||||
|
dt.Columns.Add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
object[] values = new object[dt.Columns.Count];
|
object[] values = new object[dt.Columns.Count];
|
||||||
for (int a = 0; a < values.Length; a++) if (!await dr.IsDBNullAsync(a)) values[a] = await dr.GetFieldValueAsync<object>(a);
|
for (int a = 0; a < values.Length; a++) if (!await dr.IsDBNullAsync(a)) values[a] = await dr.GetFieldValueAsync<object>(a);
|
||||||
@ -604,7 +624,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
await ExecuteReaderAsync(connection, transaction, async dr =>
|
await ExecuteReaderAsync(connection, transaction, async dr =>
|
||||||
{
|
{
|
||||||
if (ret.Columns.Count == 0)
|
if (ret.Columns.Count == 0)
|
||||||
for (var a = 0; a < dr.FieldCount; a++) ret.Columns.Add(dr.GetName(a));
|
for (var a = 0; a < dr.FieldCount; a++)
|
||||||
|
{
|
||||||
|
var name = dr.GetName(a);
|
||||||
|
if (ret.Columns.Contains(name)) name = $"{name}_{Guid.NewGuid().ToString("N").Substring(0, 4)}";
|
||||||
|
ret.Columns.Add(name);
|
||||||
|
}
|
||||||
object[] values = new object[ret.Columns.Count];
|
object[] values = new object[ret.Columns.Count];
|
||||||
for (int a = 0; a < values.Length; a++) if (!await dr.IsDBNullAsync(a)) values[a] = await dr.GetFieldValueAsync<object>(a);
|
for (int a = 0; a < values.Length; a++) if (!await dr.IsDBNullAsync(a)) values[a] = await dr.GetFieldValueAsync<object>(a);
|
||||||
ret.Rows.Add(values);
|
ret.Rows.Add(values);
|
||||||
|
@ -88,7 +88,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IInsert<T1> BatchOptions(int valuesLimit, int parameterLimit, bool autoTransaction = true)
|
public virtual IInsert<T1> BatchOptions(int valuesLimit, int parameterLimit, bool autoTransaction = true)
|
||||||
{
|
{
|
||||||
_batchValuesLimit = valuesLimit;
|
_batchValuesLimit = valuesLimit;
|
||||||
_batchParameterLimit = parameterLimit;
|
_batchParameterLimit = parameterLimit;
|
||||||
@ -170,6 +170,8 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
valuesLimit = valuesLimit - 1;
|
valuesLimit = valuesLimit - 1;
|
||||||
parameterLimit = parameterLimit - 1;
|
parameterLimit = parameterLimit - 1;
|
||||||
|
if (valuesLimit <= 0) valuesLimit = 1;
|
||||||
|
if (parameterLimit <= 0) parameterLimit = 999;
|
||||||
if (_source == null || _source.Any() == false) return new List<T1>[0];
|
if (_source == null || _source.Any() == false) return new List<T1>[0];
|
||||||
if (_source.Count == 1) return new[] { _source };
|
if (_source.Count == 1) return new[] { _source };
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public bool Any()
|
public bool Any()
|
||||||
{
|
{
|
||||||
this.Limit(1);
|
this.Limit(1);
|
||||||
return this.ToList<int>("1 as1").Sum() > 0; //这里的 Sum 为了分表查询
|
return this.ToList<int>($"{1}{_commonUtils.FieldAsAlias("as1")}").Sum() > 0; //这里的 Sum 为了分表查询
|
||||||
}
|
}
|
||||||
|
|
||||||
public long Count()
|
public long Count()
|
||||||
@ -164,7 +164,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_orderby = null; //解决 select count(1) from t order by id 这样的 SQL 错误
|
_orderby = null; //解决 select count(1) from t order by id 这样的 SQL 错误
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return this.ToList<int>("count(1) as1").Sum(); //这里的 Sum 为了分表查询
|
return this.ToList<int>($"count(1){_commonUtils.FieldAsAlias("as1")}").Sum(); //这里的 Sum 为了分表查询
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -599,7 +599,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||||
field.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, $"{tbi.Alias}.{quoteName}"));
|
field.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, $"{tbi.Alias}.{quoteName}"));
|
||||||
++index;
|
++index;
|
||||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||||
else dicfield.Add(quoteName, true);
|
else dicfield.Add(quoteName, true);
|
||||||
++colidx;
|
++colidx;
|
||||||
}
|
}
|
||||||
@ -730,7 +730,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||||
field.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
|
field.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
|
||||||
++index;
|
++index;
|
||||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||||
else dicfield.Add(quoteName, true);
|
else dicfield.Add(quoteName, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -754,7 +754,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
field.Append(_commonUtils.QuoteReadColumn(col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
|
field.Append(_commonUtils.QuoteReadColumn(col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
|
||||||
++index;
|
++index;
|
||||||
++otherindex;
|
++otherindex;
|
||||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||||
else dicfield.Add(quoteName, true);
|
else dicfield.Add(quoteName, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -851,7 +851,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||||
field.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
|
field.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
|
||||||
++index;
|
++index;
|
||||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||||
else dicfield.Add(quoteName, true);
|
else dicfield.Add(quoteName, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -868,7 +868,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
var quoteName = _commonUtils.QuoteSqlName(col2.Attribute.Name);
|
var quoteName = _commonUtils.QuoteSqlName(col2.Attribute.Name);
|
||||||
field.Append(_commonUtils.QuoteReadColumn(col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
|
field.Append(_commonUtils.QuoteReadColumn(col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
|
||||||
++index;
|
++index;
|
||||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||||
else dicfield.Add(quoteName, true);
|
else dicfield.Add(quoteName, true);
|
||||||
child.Childs.Add(new ReadAnonymousTypeInfo
|
child.Childs.Add(new ReadAnonymousTypeInfo
|
||||||
{
|
{
|
||||||
@ -946,6 +946,8 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (_orm.CodeFirst.IsSyncStructureToUpper) name = name.ToUpper();
|
if (_orm.CodeFirst.IsSyncStructureToUpper) name = name.ToUpper();
|
||||||
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(tb.Table.Type, name);
|
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(tb.Table.Type, name);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
name = name.Replace("\r\n", "\r\n ");
|
||||||
}
|
}
|
||||||
dict.Add(tb.Table.Type, name);
|
dict.Add(tb.Table.Type, name);
|
||||||
}
|
}
|
||||||
@ -1035,12 +1037,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
protected double InternalAvg(Expression exp)
|
protected double InternalAvg(Expression exp)
|
||||||
{
|
{
|
||||||
var list = this.ToList<double>($"avg({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1");
|
var list = this.ToList<double>($"avg({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}");
|
||||||
return list.Sum() / list.Count;
|
return list.Sum() / list.Count;
|
||||||
}
|
}
|
||||||
protected TMember InternalMax<TMember>(Expression exp) => this.ToList<TMember>($"max({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1").Max();
|
protected TMember InternalMax<TMember>(Expression exp) => this.ToList<TMember>($"max({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}").Max();
|
||||||
protected TMember InternalMin<TMember>(Expression exp) => this.ToList<TMember>($"min({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1").Min();
|
protected TMember InternalMin<TMember>(Expression exp) => this.ToList<TMember>($"min({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}").Min();
|
||||||
protected decimal InternalSum(Expression exp) => this.ToList<decimal>($"sum({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1").Sum();
|
protected decimal InternalSum(Expression exp) => this.ToList<decimal>($"sum({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}").Sum();
|
||||||
|
|
||||||
protected ISelectGrouping<TKey, TValue> InternalGroupBy<TKey, TValue>(Expression columns)
|
protected ISelectGrouping<TKey, TValue> InternalGroupBy<TKey, TValue>(Expression columns)
|
||||||
{
|
{
|
||||||
@ -1118,7 +1120,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
async public Task<bool> AnyAsync()
|
async public Task<bool> AnyAsync()
|
||||||
{
|
{
|
||||||
this.Limit(1);
|
this.Limit(1);
|
||||||
return (await this.ToListAsync<int>("1 as1")).Sum() > 0; //这里的 Sum 为了分表查询
|
return (await this.ToListAsync<int>($"1{_commonUtils.FieldAsAlias("as1")}")).Sum() > 0; //这里的 Sum 为了分表查询
|
||||||
}
|
}
|
||||||
|
|
||||||
async public Task<long> CountAsync()
|
async public Task<long> CountAsync()
|
||||||
@ -1127,7 +1129,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_orderby = null;
|
_orderby = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (await this.ToListAsync<int>("count(1) as1")).Sum(); //这里的 Sum 为了分表查询
|
return (await this.ToListAsync<int>($"count(1){_commonUtils.FieldAsAlias("as1")}")).Sum(); //这里的 Sum 为了分表查询
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -1312,12 +1314,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
async protected Task<double> InternalAvgAsync(Expression exp)
|
async protected Task<double> InternalAvgAsync(Expression exp)
|
||||||
{
|
{
|
||||||
var list = await this.ToListAsync<double>($"avg({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1");
|
var list = await this.ToListAsync<double>($"avg({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}");
|
||||||
return list.Sum() / list.Count;
|
return list.Sum() / list.Count;
|
||||||
}
|
}
|
||||||
async protected Task<TMember> InternalMaxAsync<TMember>(Expression exp) => (await this.ToListAsync<TMember>($"max({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1")).Max();
|
async protected Task<TMember> InternalMaxAsync<TMember>(Expression exp) => (await this.ToListAsync<TMember>($"max({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}")).Max();
|
||||||
async protected Task<TMember> InternalMinAsync<TMember>(Expression exp) => (await this.ToListAsync<TMember>($"min({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1")).Min();
|
async protected Task<TMember> InternalMinAsync<TMember>(Expression exp) => (await this.ToListAsync<TMember>($"min({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}")).Min();
|
||||||
async protected Task<decimal> InternalSumAsync(Expression exp) => (await this.ToListAsync<decimal>($"sum({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}) as1")).Sum();
|
async protected Task<decimal> InternalSumAsync(Expression exp) => (await this.ToListAsync<decimal>($"sum({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)}){_commonUtils.FieldAsAlias("as1")}")).Sum();
|
||||||
|
|
||||||
protected Task<List<TReturn>> InternalToListAsync<TReturn>(Expression select) => this.ToListMapReaderAsync<TReturn>(this.GetExpressionField(select));
|
protected Task<List<TReturn>> InternalToListAsync<TReturn>(Expression select) => this.ToListMapReaderAsync<TReturn>(this.GetExpressionField(select));
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
case "Where": this.InternalWhere(expCall.Arguments[0]); break;
|
case "Where": this.InternalWhere(expCall.Arguments[0]); break;
|
||||||
case "WhereIf":
|
case "WhereIf":
|
||||||
var whereIfCond = _commonExpression.ExpressionSelectColumn_MemberAccess(null, null, SelectTableInfoType.From, expCall.Arguments[0], false, null);
|
var whereIfCond = _commonExpression.ExpressionSelectColumn_MemberAccess(null, null, SelectTableInfoType.From, expCall.Arguments[0], false, null);
|
||||||
if (whereIfCond == "1" || whereIfCond == "'t'")
|
if (whereIfCond == "1" || whereIfCond == "'t'" || whereIfCond == "-1") //MsAccess -1
|
||||||
this.InternalWhere(expCall.Arguments[1]);
|
this.InternalWhere(expCall.Arguments[1]);
|
||||||
break;
|
break;
|
||||||
case "OrderBy":
|
case "OrderBy":
|
||||||
@ -73,7 +73,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (expCall.Arguments.Count == 2 && expCall.Arguments[0].Type == typeof(bool))
|
if (expCall.Arguments.Count == 2 && expCall.Arguments[0].Type == typeof(bool))
|
||||||
{
|
{
|
||||||
var ifcond = _commonExpression.ExpressionSelectColumn_MemberAccess(null, null, SelectTableInfoType.From, expCall.Arguments[0], false, null);
|
var ifcond = _commonExpression.ExpressionSelectColumn_MemberAccess(null, null, SelectTableInfoType.From, expCall.Arguments[0], false, null);
|
||||||
if (ifcond == "1" || ifcond == "'t'")
|
if (ifcond == "1" || ifcond == "'t'" || ifcond == "-1")//MsAccess -1
|
||||||
this.InternalOrderByDescending(expCall.Arguments.LastOrDefault());
|
this.InternalOrderByDescending(expCall.Arguments.LastOrDefault());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
public List<TReturn> Select<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select) => ToList(select);
|
public List<TReturn> Select<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select) => ToList(select);
|
||||||
|
|
||||||
public string ToSql<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select)
|
public string ToSql<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select, FieldAliasOptions fieldAlias = FieldAliasOptions.AsIndex)
|
||||||
{
|
{
|
||||||
var map = new ReadAnonymousTypeInfo();
|
var map = new ReadAnonymousTypeInfo();
|
||||||
var field = new StringBuilder();
|
var field = new StringBuilder();
|
||||||
var index = 0;
|
var index = fieldAlias == FieldAliasOptions.AsProperty ? CommonExpression.ReadAnonymousFieldAsCsName : 0;
|
||||||
|
|
||||||
_comonExp.ReadAnonymousField(null, field, map, ref index, select, getSelectGroupingMapString, null, true);
|
_comonExp.ReadAnonymousField(null, field, map, ref index, select, getSelectGroupingMapString, null, true);
|
||||||
var method = _select.GetType().GetMethod("ToSql", new[] { typeof(string) });
|
var method = _select.GetType().GetMethod("ToSql", new[] { typeof(string) });
|
||||||
@ -163,7 +163,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long Count() => long.TryParse(string.Concat(_orm.Ado.ExecuteScalar($"select count(1) from ({this.ToSql("1 as1")}) fta")), out var trylng) ? trylng : default(long);
|
public long Count() => long.TryParse(string.Concat(_orm.Ado.ExecuteScalar($"select count(1) from ({this.ToSql($"1{_comonExp._common.FieldAsAlias("as1")}")}) fta")), out var trylng) ? trylng : default(long);
|
||||||
public ISelectGrouping<TKey, TValue> Count(out long count)
|
public ISelectGrouping<TKey, TValue> Count(out long count)
|
||||||
{
|
{
|
||||||
count = this.Count();
|
count = this.Count();
|
||||||
@ -172,7 +172,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
async public Task<long> CountAsync() => long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync($"select count(1) from ({this.ToSql("1 as1")}) fta")), out var trylng) ? trylng : default(long);
|
async public Task<long> CountAsync() => long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync($"select count(1) from ({this.ToSql($"1{_comonExp._common.FieldAsAlias("as1")}")}) fta")), out var trylng) ? trylng : default(long);
|
||||||
|
|
||||||
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select)
|
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IUpdate<T1> BatchOptions(int rowsLimit, int parameterLimit, bool autoTransaction = true)
|
public virtual IUpdate<T1> BatchOptions(int rowsLimit, int parameterLimit, bool autoTransaction = true)
|
||||||
{
|
{
|
||||||
_batchRowsLimit = rowsLimit;
|
_batchRowsLimit = rowsLimit;
|
||||||
_batchParameterLimit = parameterLimit;
|
_batchParameterLimit = parameterLimit;
|
||||||
@ -117,6 +117,8 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
valuesLimit = valuesLimit - 1;
|
valuesLimit = valuesLimit - 1;
|
||||||
parameterLimit = parameterLimit - 1;
|
parameterLimit = parameterLimit - 1;
|
||||||
|
if (valuesLimit <= 0) valuesLimit = 1;
|
||||||
|
if (parameterLimit <= 0) parameterLimit = 999;
|
||||||
if (_source == null || _source.Any() == false) return new List<T1>[0];
|
if (_source == null || _source.Any() == false) return new List<T1>[0];
|
||||||
if (_source.Count == 1) return new[] { _source };
|
if (_source.Count == 1) return new[] { _source };
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ namespace FreeSql.Internal
|
|||||||
public abstract string NowUtc { get; }
|
public abstract string NowUtc { get; }
|
||||||
public abstract string QuoteWriteParamter(Type type, string paramterName);
|
public abstract string QuoteWriteParamter(Type type, string paramterName);
|
||||||
public abstract string QuoteReadColumn(Type type, string columnName);
|
public abstract string QuoteReadColumn(Type type, string columnName);
|
||||||
|
public virtual string FieldAsAlias(string alias) => $" {alias}";
|
||||||
|
public virtual string IIF(string test, string ifTrue, string ifElse) => $"case when {test} then {ifTrue} else {ifElse} end";
|
||||||
|
|
||||||
public IFreeSql _orm { get; set; }
|
public IFreeSql _orm { get; set; }
|
||||||
public ICodeFirst CodeFirst => _orm.CodeFirst;
|
public ICodeFirst CodeFirst => _orm.CodeFirst;
|
||||||
|
@ -199,7 +199,7 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
case DataType.MySql:
|
case DataType.MySql:
|
||||||
case DataType.OdbcMySql:
|
case DataType.OdbcMySql:
|
||||||
if (strlen < 0) colattr.DbType = "text";
|
if (strlen < 0) colattr.DbType = "TEXT";
|
||||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||||
break;
|
break;
|
||||||
case DataType.SqlServer:
|
case DataType.SqlServer:
|
||||||
@ -209,7 +209,7 @@ namespace FreeSql.Internal
|
|||||||
break;
|
break;
|
||||||
case DataType.PostgreSQL:
|
case DataType.PostgreSQL:
|
||||||
case DataType.OdbcPostgreSQL:
|
case DataType.OdbcPostgreSQL:
|
||||||
if (strlen < 0) colattr.DbType = "text";
|
if (strlen < 0) colattr.DbType = "TEXT";
|
||||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||||
break;
|
break;
|
||||||
case DataType.Oracle:
|
case DataType.Oracle:
|
||||||
@ -219,7 +219,12 @@ namespace FreeSql.Internal
|
|||||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||||
break;
|
break;
|
||||||
case DataType.Sqlite:
|
case DataType.Sqlite:
|
||||||
if (strlen < 0) colattr.DbType = "text";
|
if (strlen < 0) colattr.DbType = "TEXT";
|
||||||
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||||
|
break;
|
||||||
|
case DataType.MsAccess:
|
||||||
|
charPatten = @"(CHAR|CHAR2|CHARACTER|TEXT)\s*(\([^\)]*\))?";
|
||||||
|
if (strlen < 0) colattr.DbType = "LONGTEXT";
|
||||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
109
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessDelete.cs
Normal file
109
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessDelete.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess.Curd
|
||||||
|
{
|
||||||
|
|
||||||
|
class MsAccessDelete<T1> : Internal.CommonProvider.DeleteProvider<T1> where T1 : class
|
||||||
|
{
|
||||||
|
public MsAccessDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||||
|
: base(orm, commonUtils, commonExpression, dywhere)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<T1> ExecuteDeleted()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append(" OUTPUT ");
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sb.Append(", ");
|
||||||
|
sb.Append("DELETED.").Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
|
||||||
|
var validx = sql.IndexOf(" WHERE ");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||||
|
sb.Insert(0, sql.Substring(0, validx));
|
||||||
|
sb.Append(sql.Substring(validx));
|
||||||
|
|
||||||
|
sql = sb.ToString();
|
||||||
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
async public override Task<List<T1>> ExecuteDeletedAsync()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append(" OUTPUT ");
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sb.Append(", ");
|
||||||
|
sb.Append("DELETED.").Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
|
||||||
|
var validx = sql.IndexOf(" WHERE ");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||||
|
sb.Insert(0, sql.Substring(0, validx));
|
||||||
|
sb.Append(sql.Substring(validx));
|
||||||
|
|
||||||
|
sql = sb.ToString();
|
||||||
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
183
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessInsert.cs
Normal file
183
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessInsert.cs
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using SafeObjectPool;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess.Curd
|
||||||
|
{
|
||||||
|
|
||||||
|
class MsAccessInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class
|
||||||
|
{
|
||||||
|
public MsAccessInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||||
|
: base(orm, commonUtils, commonExpression)
|
||||||
|
{
|
||||||
|
_batchAutoTransaction = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//蛋疼的 access 插入只能一条一条执行,不支持 values(..),(..) 也不支持 select .. UNION ALL select ..
|
||||||
|
public override int ExecuteAffrows() => base.SplitExecuteAffrows(1, 1000);
|
||||||
|
public override long ExecuteIdentity() => base.SplitExecuteIdentity(1, 1000);
|
||||||
|
public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(1, 1000);
|
||||||
|
|
||||||
|
public override IInsert<T1> BatchOptions(int valuesLimit, int parameterLimit, bool autoTransaction = true) =>
|
||||||
|
throw new NotImplementedException("蛋疼的 access 插入只能一条一条执行,不支持 values(..),(..) 也不支持 select .. UNION ALL select ..");
|
||||||
|
|
||||||
|
protected override int RawExecuteAffrows()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
return affrows;
|
||||||
|
}
|
||||||
|
protected override long RawExecuteIdentity()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, string.Concat(sql, "; SELECT @@identity;"), _params);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
var isUseConnection = _connection != null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isUseConnection == false)
|
||||||
|
{
|
||||||
|
using (var conn = _orm.Ado.MasterPool.Get())
|
||||||
|
{
|
||||||
|
_connection = conn.Value;
|
||||||
|
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, "SELECT @@identity", _params)), out ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, "SELECT @@identity", _params)), out ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (isUseConnection == false) _connection = null;
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
protected override List<T1> RawExecuteInserted()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||||
|
|
||||||
|
var ret = _source.ToList();
|
||||||
|
this.RawExecuteAffrows();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(1000, 2100);
|
||||||
|
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(1000, 2100);
|
||||||
|
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(1000, 2100);
|
||||||
|
|
||||||
|
async protected override Task<int> RawExecuteAffrowsAsync()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
return affrows;
|
||||||
|
}
|
||||||
|
async protected override Task<long> RawExecuteIdentityAsync()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, string.Concat(sql, "; SELECT @@identity;"), _params);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
var isUseConnection = _connection != null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isUseConnection == false)
|
||||||
|
{
|
||||||
|
using (var conn = await _orm.Ado.MasterPool.GetAsync())
|
||||||
|
{
|
||||||
|
_connection = conn.Value;
|
||||||
|
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, "SELECT @@identity", _params)), out ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, "SELECT @@identity", _params)), out ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (isUseConnection == false) _connection = null;
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
async protected override Task<List<T1>> RawExecuteInsertedAsync()
|
||||||
|
{
|
||||||
|
var sql = this.ToSql();
|
||||||
|
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||||
|
|
||||||
|
var ret = _source.ToList();
|
||||||
|
await this.RawExecuteAffrowsAsync();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
194
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessSelect.cs
Normal file
194
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessSelect.cs
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess.Curd
|
||||||
|
{
|
||||||
|
|
||||||
|
class MsAccessSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class
|
||||||
|
{
|
||||||
|
|
||||||
|
internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _commonExpression, string _select, bool _distinct, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, List<Dictionary<Type, string>> tbUnions, Func<Type, string, string> _aliasRule, string _tosqlAppendContent, List<LambdaExpression> _whereCascadeExpression, IFreeSql _orm)
|
||||||
|
{
|
||||||
|
if (_orm.CodeFirst.IsAutoSyncStructure)
|
||||||
|
_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
|
||||||
|
|
||||||
|
if (_whereCascadeExpression.Any())
|
||||||
|
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
|
||||||
|
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
var tbUnionsGt0 = tbUnions.Count > 1;
|
||||||
|
for (var tbUnionsIdx = 0; tbUnionsIdx < tbUnions.Count; tbUnionsIdx++)
|
||||||
|
{
|
||||||
|
if (tbUnionsIdx > 0) sb.Append(" \r\n\r\nUNION ALL\r\n\r\n");
|
||||||
|
if (tbUnionsGt0) sb.Append(_select).Append(" * from (");
|
||||||
|
var tbUnion = tbUnions[tbUnionsIdx];
|
||||||
|
|
||||||
|
var sbnav = new StringBuilder();
|
||||||
|
sb.Append(_select);
|
||||||
|
if (_distinct) sb.Append("DISTINCT ");
|
||||||
|
if (_limit > 0) sb.Append("TOP ").Append(_skip + _limit).Append(" ");
|
||||||
|
sb.Append(field);
|
||||||
|
if (_skip > 0)
|
||||||
|
throw new NotImplementedException("FreeSql.Provider.MsAccess 未实现 Skip/Offset 功能,如果需要分页请使用判断上一次 id");
|
||||||
|
sb.Append(" \r\nFROM ");
|
||||||
|
var fromIndex = sb.Length;
|
||||||
|
var ioinCounter = 0;
|
||||||
|
var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
|
||||||
|
var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
|
||||||
|
for (var a = 0; a < tbsfrom.Length; a++)
|
||||||
|
{
|
||||||
|
sb.Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[a].Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Alias) ?? tbsfrom[a].Alias);
|
||||||
|
if (tbsjoin.Length > 0)
|
||||||
|
{
|
||||||
|
//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
|
||||||
|
for (var b = 1; b < tbsfrom.Length; b++)
|
||||||
|
{
|
||||||
|
if (ioinCounter++ > 0) sb.Insert(fromIndex, "(").Append(") ");
|
||||||
|
sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[b].Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Alias) ?? tbsfrom[b].Alias);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(tbsfrom[b].NavigateCondition) && string.IsNullOrEmpty(tbsfrom[b].On) && string.IsNullOrEmpty(tbsfrom[b].Cascade)) sb.Append(" ON 1 = 1");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var onSql = tbsfrom[b].NavigateCondition ?? tbsfrom[b].On;
|
||||||
|
sb.Append(" ON (").Append(onSql);
|
||||||
|
if (string.IsNullOrEmpty(tbsfrom[b].Cascade) == false)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(onSql)) sb.Append(tbsfrom[b].Cascade);
|
||||||
|
else sb.Append(" AND (").Append(tbsfrom[b].Cascade).Append(")");
|
||||||
|
}
|
||||||
|
sb.Append(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(tbsfrom[a].NavigateCondition)) sbnav.Append(" AND (").Append(tbsfrom[a].NavigateCondition).Append(")");
|
||||||
|
if (!string.IsNullOrEmpty(tbsfrom[a].On)) sbnav.Append(" AND (").Append(tbsfrom[a].On).Append(")");
|
||||||
|
if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].Cascade)) sbnav.Append(" AND (").Append(tbsfrom[a].Cascade).Append(")");
|
||||||
|
}
|
||||||
|
if (a < tbsfrom.Length - 1) sb.Append(", ");
|
||||||
|
}
|
||||||
|
foreach (var tb in tbsjoin)
|
||||||
|
{
|
||||||
|
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||||
|
switch (tb.Type)
|
||||||
|
{
|
||||||
|
case SelectTableInfoType.LeftJoin:
|
||||||
|
if (ioinCounter++ > 0) sb.Insert(fromIndex, "(").Append(") ");
|
||||||
|
sb.Append(" \r\nLEFT JOIN ");
|
||||||
|
break;
|
||||||
|
case SelectTableInfoType.InnerJoin:
|
||||||
|
if (ioinCounter++ > 0) sb.Insert(fromIndex, "(").Append(") ");
|
||||||
|
sb.Append(" \r\nINNER JOIN ");
|
||||||
|
break;
|
||||||
|
case SelectTableInfoType.RightJoin:
|
||||||
|
if (ioinCounter++ > 0) sb.Insert(fromIndex, "(").Append(") ");
|
||||||
|
sb.Append(" \r\nRIGHT JOIN ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sb.Append(_commonUtils.QuoteSqlName(tbUnion[tb.Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tb.Table.Type, tb.Alias) ?? tb.Alias).Append(" ON (").Append(tb.On ?? tb.NavigateCondition);
|
||||||
|
if (!string.IsNullOrEmpty(tb.Cascade)) sb.Append(" AND (").Append(tb.Cascade).Append(")");
|
||||||
|
if (!string.IsNullOrEmpty(tb.On) && !string.IsNullOrEmpty(tb.NavigateCondition)) sbnav.Append(" AND (").Append(tb.NavigateCondition).Append(")");
|
||||||
|
sb.Append(")");
|
||||||
|
}
|
||||||
|
if (_join.Length > 0)
|
||||||
|
{
|
||||||
|
sb.Append(Regex.Replace(_join.ToString(), @" \r\n(LEFT|INNER|RIGHT) JOIN ", m =>
|
||||||
|
{
|
||||||
|
if (ioinCounter++ > 0)
|
||||||
|
{
|
||||||
|
sb.Insert(fromIndex, "(").Append(") ");
|
||||||
|
return $") {m.Groups[0].Value}";
|
||||||
|
}
|
||||||
|
return m.Groups[0].Value;
|
||||||
|
}, RegexOptions.IgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
sbnav.Append(_where);
|
||||||
|
if (!string.IsNullOrEmpty(_tables[0].Cascade))
|
||||||
|
sbnav.Append(" AND (").Append(_tables[0].Cascade).Append(")");
|
||||||
|
|
||||||
|
if (sbnav.Length > 0)
|
||||||
|
{
|
||||||
|
sb.Append(" \r\nWHERE ").Append(sbnav.Remove(0, 5));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(_groupby) == false)
|
||||||
|
{
|
||||||
|
sb.Append(_groupby);
|
||||||
|
if (string.IsNullOrEmpty(_having) == false)
|
||||||
|
sb.Append(" \r\nHAVING ").Append(_having.Substring(5));
|
||||||
|
}
|
||||||
|
sb.Append(_orderby);
|
||||||
|
|
||||||
|
sbnav.Clear();
|
||||||
|
if (tbUnionsGt0) sb.Append(") ftb");
|
||||||
|
}
|
||||||
|
return sb.Append(_tosqlAppendContent).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MsAccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override ISelect<T1, T2> From<T2>(Expression<Func<ISelectFromExpression<T1>, T2, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3> From<T2, T3>(Expression<Func<ISelectFromExpression<T1>, T2, T3, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4> From<T2, T3, T4>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4, T5> From<T2, T3, T4, T5>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4, T5>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4, T5, T6> From<T2, T3, T4, T5, T6>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4, T5, T6>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4, T5, T6, T7> From<T2, T3, T4, T5, T6, T7>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4, T5, T6, T7>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new AccessSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); MsAccessSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||||
|
public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
class AccessSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class
|
||||||
|
{
|
||||||
|
public AccessSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||||
|
public override string ToSql(string field = null) => MsAccessSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereCascadeExpression, _orm);
|
||||||
|
}
|
||||||
|
}
|
79
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessUpdate.cs
Normal file
79
Providers/FreeSql.Provider.MsAccess/Curd/MsAccessUpdate.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess.Curd
|
||||||
|
{
|
||||||
|
|
||||||
|
class MsAccessUpdate<T1> : Internal.CommonProvider.UpdateProvider<T1> where T1 : class
|
||||||
|
{
|
||||||
|
|
||||||
|
public MsAccessUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||||
|
: base(orm, commonUtils, commonExpression, dywhere)
|
||||||
|
{
|
||||||
|
_batchAutoTransaction = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//蛋疼的 access 更新只能一条一条执行,不支持 case .. when .. then .. end,也不支持事务
|
||||||
|
public override int ExecuteAffrows() => base.SplitExecuteAffrows(1, 1000);
|
||||||
|
public override List<T1> ExecuteUpdated() => base.SplitExecuteUpdated(1, 1000);
|
||||||
|
|
||||||
|
public override IUpdate<T1> BatchOptions(int rowsLimit, int parameterLimit, bool autoTransaction = true) =>
|
||||||
|
throw new NotImplementedException("蛋疼的 access 插入只能一条一条执行,不支持 values(..),(..) 也不支持 select .. UNION ALL select ..");
|
||||||
|
|
||||||
|
protected override List<T1> RawExecuteUpdated()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys)
|
||||||
|
{
|
||||||
|
if (_table.Primarys.Length == 1)
|
||||||
|
{
|
||||||
|
caseWhen.Append(_commonUtils.QuoteReadColumn(_table.Primarys.First().Attribute.MapType, _commonUtils.QuoteSqlName(_table.Primarys.First().Attribute.Name)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
caseWhen.Append("(");
|
||||||
|
var pkidx = 0;
|
||||||
|
foreach (var pk in _table.Primarys)
|
||||||
|
{
|
||||||
|
if (pkidx > 0) caseWhen.Append(", ");
|
||||||
|
caseWhen.Append(MsAccessUtils.GetCastSql(_commonUtils.QuoteReadColumn(_table.Primarys.First().Attribute.MapType, _commonUtils.QuoteSqlName(pk.Attribute.Name)), typeof(string)));
|
||||||
|
++pkidx;
|
||||||
|
}
|
||||||
|
caseWhen.Append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d)
|
||||||
|
{
|
||||||
|
if (_table.Primarys.Length == 1)
|
||||||
|
{
|
||||||
|
sb.Append(_commonUtils.FormatSql("{0}", _table.Primarys.First().GetMapValue(d)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pkidx = 0;
|
||||||
|
foreach (var pk in _table.Primarys)
|
||||||
|
{
|
||||||
|
if (pkidx > 0) sb.Append(", ");
|
||||||
|
sb.Append(MsAccessUtils.GetCastSql(_commonUtils.FormatSql("{0}", pk.GetMapValue(d)), typeof(string)));
|
||||||
|
++pkidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(500, 2100);
|
||||||
|
public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(500, 2100);
|
||||||
|
|
||||||
|
protected override Task<List<T1>> RawExecuteUpdatedAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||||
|
<Version>0.12.21</Version>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<Authors>YeXiangQin</Authors>
|
||||||
|
<Description>FreeSql 数据库 Ms Access 实现</Description>
|
||||||
|
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||||
|
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
||||||
|
<RepositoryType>git</RepositoryType>
|
||||||
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
<PackageTags>FreeSql;ORM;Access</PackageTags>
|
||||||
|
<PackageId>$(AssemblyName)</PackageId>
|
||||||
|
<PackageIcon>logo.png</PackageIcon>
|
||||||
|
<Title>$(AssemblyName)</Title>
|
||||||
|
<IsPackable>true</IsPackable>
|
||||||
|
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="../../logo.png" Pack="true" PackagePath="\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||||
|
<PackageReference Include="System.Data.OleDb" Version="4.7.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
|
||||||
|
<DefineConstants>net40</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
public static partial class FreeSqlMsAccessGlobalExtensions
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="that"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string FormatAccess(this string that, params object[] args) => _accessAdo.Addslashes(that, args);
|
||||||
|
static FreeSql.MsAccess.MsAccessAdo _accessAdo = new FreeSql.MsAccess.MsAccessAdo();
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using SafeObjectPool;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess
|
||||||
|
{
|
||||||
|
class MsAccessAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||||
|
{
|
||||||
|
public MsAccessAdo() : base(DataType.MsAccess) { }
|
||||||
|
public MsAccessAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.MsAccess)
|
||||||
|
{
|
||||||
|
base._util = util;
|
||||||
|
if (connectionFactory != null)
|
||||||
|
{
|
||||||
|
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MsAccess, connectionFactory);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||||
|
MasterPool = new MsAccessConnectionPool("主库", masterConnectionString, null, null);
|
||||||
|
if (slaveConnectionStrings != null)
|
||||||
|
{
|
||||||
|
foreach (var slaveConnectionString in slaveConnectionStrings)
|
||||||
|
{
|
||||||
|
var slavePool = new MsAccessConnectionPool($"从库{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
|
||||||
|
SlavePools.Add(slavePool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
|
{
|
||||||
|
if (param == null) return "NULL";
|
||||||
|
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || mapType.IsArrayOrList()))
|
||||||
|
param = Utils.GetDataReaderValue(mapType, param);
|
||||||
|
if (param is bool || param is bool?)
|
||||||
|
return (bool)param ? -1 : 0;
|
||||||
|
else if (param is string || param is char)
|
||||||
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||||
|
else if (param is Enum)
|
||||||
|
return ((Enum)param).ToInt64();
|
||||||
|
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||||
|
return param;
|
||||||
|
else if (param is DateTime || param is DateTime?)
|
||||||
|
{
|
||||||
|
if (param.Equals(DateTime.MinValue) == true) param = new DateTime(1970, 1, 1);
|
||||||
|
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
||||||
|
}
|
||||||
|
else if (param is TimeSpan || param is TimeSpan?)
|
||||||
|
return ((TimeSpan)param).TotalSeconds;
|
||||||
|
else if (param is IEnumerable)
|
||||||
|
return AddslashesIEnumerable(param, mapType, mapColumn);
|
||||||
|
|
||||||
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DbCommand CreateCommand()
|
||||||
|
{
|
||||||
|
return new OleDbCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||||
|
{
|
||||||
|
var rawPool = pool as MsAccessConnectionPool;
|
||||||
|
if (rawPool != null) rawPool.Return(conn, ex);
|
||||||
|
else pool.Return(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,242 @@
|
|||||||
|
using SafeObjectPool;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess
|
||||||
|
{
|
||||||
|
|
||||||
|
class MsAccessConnectionPool : ObjectPool<DbConnection>
|
||||||
|
{
|
||||||
|
|
||||||
|
internal Action availableHandler;
|
||||||
|
internal Action unavailableHandler;
|
||||||
|
|
||||||
|
public MsAccessConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
|
||||||
|
{
|
||||||
|
var policy = new AccessConnectionPoolPolicy
|
||||||
|
{
|
||||||
|
_pool = this,
|
||||||
|
Name = name
|
||||||
|
};
|
||||||
|
this.Policy = policy;
|
||||||
|
policy.ConnectionString = connectionString;
|
||||||
|
|
||||||
|
this.availableHandler = availableHandler;
|
||||||
|
this.unavailableHandler = unavailableHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
|
||||||
|
{
|
||||||
|
if (exception != null && exception is OleDbException)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (obj.Value.Ping() == false)
|
||||||
|
{
|
||||||
|
|
||||||
|
base.SetUnavailable(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base.Return(obj, isRecreate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessConnectionPoolPolicy : IPolicy<DbConnection>
|
||||||
|
{
|
||||||
|
|
||||||
|
internal MsAccessConnectionPool _pool;
|
||||||
|
public string Name { get; set; } = "Microsoft Access OleDbConnection 对象池";
|
||||||
|
public int PoolSize { get; set; } = 100;
|
||||||
|
public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(30);
|
||||||
|
public TimeSpan IdleTimeout { get; set; } = TimeSpan.Zero;
|
||||||
|
public int AsyncGetCapacity { get; set; } = 10000;
|
||||||
|
public bool IsThrowGetTimeoutException { get; set; } = true;
|
||||||
|
public int CheckAvailableInterval { get; set; } = 5;
|
||||||
|
|
||||||
|
private string _connectionString;
|
||||||
|
public string ConnectionString
|
||||||
|
{
|
||||||
|
get => _connectionString;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_connectionString = value ?? "";
|
||||||
|
|
||||||
|
var pattern = @"Max\s*pool\s*size\s*=\s*(\d+)";
|
||||||
|
Match m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
if (int.TryParse(m.Groups[1].Value, out var poolsize) && poolsize > 0)
|
||||||
|
PoolSize = poolsize;
|
||||||
|
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern = @"Connection\s*LifeTime\s*=\s*(\d+)";
|
||||||
|
m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
IdleTimeout = TimeSpan.FromSeconds(int.Parse(m.Groups[1].Value));
|
||||||
|
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
var minPoolSize = 0;
|
||||||
|
pattern = @"Min\s*pool\s*size\s*=\s*(\d+)";
|
||||||
|
m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
minPoolSize = int.Parse(m.Groups[1].Value);
|
||||||
|
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeSql.Internal.CommonUtils.PrevReheatConnectionPool(_pool, minPoolSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnCheckAvailable(Object<DbConnection> obj)
|
||||||
|
{
|
||||||
|
if (obj.Value.State == ConnectionState.Closed) obj.Value.Open();
|
||||||
|
return obj.Value.Ping(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbConnection OnCreate()
|
||||||
|
{
|
||||||
|
var conn = new OleDbConnection(_connectionString);
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDestroy(DbConnection obj)
|
||||||
|
{
|
||||||
|
if (obj.State != ConnectionState.Closed) obj.Close();
|
||||||
|
obj.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnGet(Object<DbConnection> obj)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (_pool.IsAvailable)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (obj.Value == null)
|
||||||
|
{
|
||||||
|
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
|
||||||
|
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
obj.Value.Open();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (_pool.SetUnavailable(ex) == true)
|
||||||
|
throw new Exception($"【{this.Name}】状态不可用,等待后台检查程序恢复方可使用。{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (_pool.IsAvailable)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (obj.Value == null)
|
||||||
|
{
|
||||||
|
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
|
||||||
|
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await obj.Value.OpenAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (_pool.SetUnavailable(ex) == true)
|
||||||
|
throw new Exception($"【{this.Name}】状态不可用,等待后台检查程序恢复方可使用。{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public void OnGetTimeout()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnReturn(Object<DbConnection> obj)
|
||||||
|
{
|
||||||
|
if (obj.Value.State != ConnectionState.Closed) try { obj.Value.Close(); } catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAvailable()
|
||||||
|
{
|
||||||
|
_pool.availableHandler?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnUnavailable()
|
||||||
|
{
|
||||||
|
_pool.unavailableHandler?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class DbConnectionExtensions
|
||||||
|
{
|
||||||
|
|
||||||
|
static DbCommand PingCommand(DbConnection conn)
|
||||||
|
{
|
||||||
|
var cmd = conn.CreateCommand();
|
||||||
|
cmd.CommandTimeout = 5;
|
||||||
|
cmd.CommandText = "select 1";
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
public static bool Ping(this DbConnection that, bool isThrow = false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PingCommand(that).ExecuteNonQuery();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||||
|
if (isThrow) throw;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await PingCommand(that).ExecuteNonQueryAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||||
|
if (isThrow) throw;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
458
Providers/FreeSql.Provider.MsAccess/MsAccessCodeFirst.cs
Normal file
458
Providers/FreeSql.Provider.MsAccess/MsAccessCodeFirst.cs
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess
|
||||||
|
{
|
||||||
|
|
||||||
|
class MsAccessCodeFirst : Internal.CommonProvider.CodeFirstProvider
|
||||||
|
{
|
||||||
|
public override bool IsNoneCommandParameter { get => true; set => base.IsNoneCommandParameter = true; }
|
||||||
|
public MsAccessCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { }
|
||||||
|
|
||||||
|
static object _dicCsToDbLock = new object();
|
||||||
|
static Dictionary<string, (OleDbType type, string dbtype, string dbtypeFull, bool? isUnsigned, bool? isnullable, object defaultValue)> _dicCsToDb = new Dictionary<string, (OleDbType type, string dbtype, string dbtypeFull, bool? isUnsigned, bool? isnullable, object defaultValue)>() {
|
||||||
|
{ typeof(bool).FullName, (OleDbType.Boolean, "bit","bit NOT NULL", null, false, false) },{ typeof(bool?).FullName, (OleDbType.Boolean, "bit","bit", null, true, null) },
|
||||||
|
|
||||||
|
{ typeof(sbyte).FullName, (OleDbType.TinyInt, "decimal", "decimal(3,0) NOT NULL", false, false, 0) },{ typeof(sbyte?).FullName, (OleDbType.TinyInt, "decimal", "decimal(3,0)", false, true, null) },
|
||||||
|
{ typeof(short).FullName, (OleDbType.SmallInt, "decimal","decimal(6,0) NOT NULL", false, false, 0) },{ typeof(short?).FullName, (OleDbType.SmallInt, "decimal", "decimal(6,0)", false, true, null) },
|
||||||
|
{ typeof(int).FullName, (OleDbType.Integer, "decimal", "decimal(11,0) NOT NULL", false, false, 0) },{ typeof(int?).FullName, (OleDbType.Integer, "decimal", "decimal(11,0)", false, true, null) },
|
||||||
|
{ typeof(long).FullName, (OleDbType.BigInt, "decimal","decimal(20,0) NOT NULL", false, false, 0) },{ typeof(long?).FullName, (OleDbType.BigInt, "decimal","decimal(20,0)", false, true, null) },
|
||||||
|
// access int long 类型是留给自动增长用的,所以这里全映射为 decimal
|
||||||
|
{ typeof(byte).FullName, (OleDbType.UnsignedTinyInt, "decimal","decimal(3,0) NOT NULL", true, false, 0) },{ typeof(byte?).FullName, (OleDbType.UnsignedTinyInt, "decimal","decimal(3,0)", true, true, null) },
|
||||||
|
{ typeof(ushort).FullName, (OleDbType.UnsignedSmallInt, "decimal","decimal(5,0) NOT NULL", true, false, 0) },{ typeof(ushort?).FullName, (OleDbType.UnsignedSmallInt, "decimal", "decimal(5,0)", true, true, null) },
|
||||||
|
{ typeof(uint).FullName, (OleDbType.UnsignedInt, "decimal", "decimal(10,0) NOT NULL", true, false, 0) },{ typeof(uint?).FullName, (OleDbType.UnsignedInt, "decimal", "decimal(10,0)", true, true, null) },
|
||||||
|
{ typeof(ulong).FullName, (OleDbType.UnsignedBigInt, "decimal", "decimal(20,0) NOT NULL", true, false, 0) },{ typeof(ulong?).FullName, (OleDbType.UnsignedBigInt, "decimal", "decimal(20,0)", true, true, null) },
|
||||||
|
|
||||||
|
{ typeof(double).FullName, (OleDbType.Double, "double", "double NOT NULL", false, false, 0) },{ typeof(double?).FullName, (OleDbType.Double, "double", "double", false, true, null) },
|
||||||
|
{ typeof(float).FullName, (OleDbType.Currency, "single","single NOT NULL", false, false, 0) },{ typeof(float?).FullName, (OleDbType.Currency, "single","single", false, true, null) },
|
||||||
|
{ typeof(decimal).FullName, (OleDbType.Decimal, "decimal", "decimal(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?).FullName, (OleDbType.Decimal, "decimal", "decimal(10,2)", false, true, null) },
|
||||||
|
|
||||||
|
{ typeof(TimeSpan).FullName, (OleDbType.DBTime, "datetime","datetime NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, (OleDbType.DBTime, "datetime", "datetime",false, true, null) },
|
||||||
|
{ typeof(DateTime).FullName, (OleDbType.DBTimeStamp, "datetime", "datetime NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, (OleDbType.DBTimeStamp, "datetime", "datetime", false, true, null) },
|
||||||
|
|
||||||
|
{ typeof(byte[]).FullName, (OleDbType.VarBinary, "varbinary", "varbinary(255)", false, null, new byte[0]) },
|
||||||
|
{ typeof(string).FullName, (OleDbType.VarChar, "varchar", "varchar(255)", false, null, "") },
|
||||||
|
|
||||||
|
{ typeof(Guid).FullName, (OleDbType.Guid, "varchar", "varchar(36) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?).FullName, (OleDbType.Guid, "varchar", "varchar(36)", false, true, null) },
|
||||||
|
};
|
||||||
|
|
||||||
|
public override (int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type)
|
||||||
|
{
|
||||||
|
if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new (int, string, string, bool?, object)?(((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue));
|
||||||
|
if (type.IsArray) return null;
|
||||||
|
var enumType = type.IsEnum ? type : null;
|
||||||
|
if (enumType == null && type.IsNullableType())
|
||||||
|
{
|
||||||
|
var genericTypes = type.GetGenericArguments();
|
||||||
|
if (genericTypes.Length == 1 && genericTypes.First().IsEnum) enumType = genericTypes.First();
|
||||||
|
}
|
||||||
|
if (enumType != null)
|
||||||
|
{
|
||||||
|
var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?
|
||||||
|
(OleDbType.BigInt, "decimal", $"decimal(20,0){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, Enum.GetValues(enumType).GetValue(0)) :
|
||||||
|
(OleDbType.Integer, "decimal", $"decimal(11,0){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, Enum.GetValues(enumType).GetValue(0));
|
||||||
|
if (_dicCsToDb.ContainsKey(type.FullName) == false)
|
||||||
|
{
|
||||||
|
lock (_dicCsToDbLock)
|
||||||
|
{
|
||||||
|
if (_dicCsToDb.ContainsKey(type.FullName) == false)
|
||||||
|
_dicCsToDb.Add(type.FullName, newItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ((int)newItem.Item1, newItem.Item2, newItem.Item3, newItem.Item5, newItem.Item6);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GetComparisonDDLStatements(params (Type entityType, string tableName)[] objects)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
var sbDeclare = new StringBuilder();
|
||||||
|
foreach (var obj in objects)
|
||||||
|
{
|
||||||
|
if (sb.Length > 0) sb.Append("\r\n");
|
||||||
|
var tb = _commonUtils.GetTableByEntity(obj.entityType);
|
||||||
|
if (tb == null) throw new Exception($"类型 {obj.entityType.FullName} 不可迁移");
|
||||||
|
if (tb.Columns.Any() == false) throw new Exception($"类型 {obj.entityType.FullName} 不可迁移,可迁移属性0个");
|
||||||
|
var tbname = tb.DbName;
|
||||||
|
var tboldname = tb.DbOldName; //旧表名
|
||||||
|
if (string.Compare(tbname, tboldname, true) == 0) tboldname = null;
|
||||||
|
if (string.IsNullOrEmpty(obj.tableName) == false)
|
||||||
|
{
|
||||||
|
tbname = obj.tableName;
|
||||||
|
tboldname = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sbalter = new StringBuilder();
|
||||||
|
var istmpatler = false; //创建临时表,导入数据,删除旧表,修改
|
||||||
|
var isexistsTb = false;
|
||||||
|
|
||||||
|
DataTable schemaTables = null;
|
||||||
|
using (var conn = _orm.Ado.MasterPool.Get())
|
||||||
|
{
|
||||||
|
schemaTables = conn.Value.GetSchema("Tables");
|
||||||
|
}
|
||||||
|
var schemaTablesTableNameIndex = 2;
|
||||||
|
for (var idx = 0; idx < schemaTables.Columns.Count; idx++)
|
||||||
|
if (string.Compare(schemaTables.Columns[idx].ColumnName, "TABLE_NAME", true) == 0)
|
||||||
|
{
|
||||||
|
schemaTablesTableNameIndex = idx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Func<string, bool> existsTable = tn =>
|
||||||
|
{
|
||||||
|
foreach (DataRow row in schemaTables.Rows)
|
||||||
|
if (string.Compare(row[schemaTablesTableNameIndex]?.ToString(), tn, true) == 0)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
//_orm.Ado.ExecuteScalar(CommandType.Text, $" SELECT 1 FROM MsysObjects WHERE Name='{tn}' AND Left([Name],1)<>'~' AND Left([Name],4)<>'Msys' AND Type=1 and Flags=0") != null;
|
||||||
|
};
|
||||||
|
Action<string> createTable = tn =>
|
||||||
|
{
|
||||||
|
tn = _commonUtils.QuoteSqlName(tn);
|
||||||
|
//创建表
|
||||||
|
sb.Append("CREATE TABLE ").Append(tn).Append(" ( ");
|
||||||
|
foreach (var tbcol in tb.ColumnsByPosition)
|
||||||
|
{
|
||||||
|
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name));
|
||||||
|
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTOINCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1)
|
||||||
|
sb.Append(" AUTOINCREMENT");
|
||||||
|
else
|
||||||
|
sb.Append(" ").Append(tbcol.Attribute.DbType);
|
||||||
|
sb.Append(",");
|
||||||
|
}
|
||||||
|
if (tb.Primarys.Any())
|
||||||
|
{
|
||||||
|
sb.Append(" \r\n PRIMARY KEY (");
|
||||||
|
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||||
|
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||||
|
}
|
||||||
|
sb.Remove(sb.Length - 1, 1);
|
||||||
|
sb.Append("\r\n) \r\n;\r\n");
|
||||||
|
};
|
||||||
|
Action<string> createTableIndex = tn =>
|
||||||
|
{
|
||||||
|
tn = _commonUtils.QuoteSqlName(tn);
|
||||||
|
//创建表的索引
|
||||||
|
foreach (var uk in tb.Indexes)
|
||||||
|
{
|
||||||
|
sb.Append("CREATE ");
|
||||||
|
if (uk.IsUnique) sb.Append("UNIQUE ");
|
||||||
|
sb.Append("INDEX ").Append(_commonUtils.QuoteSqlName(uk.Name)).Append(" ON ").Append(tn).Append("(");
|
||||||
|
foreach (var tbcol in uk.Columns)
|
||||||
|
{
|
||||||
|
sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name));
|
||||||
|
if (tbcol.IsDesc) sb.Append(" DESC");
|
||||||
|
sb.Append(", ");
|
||||||
|
}
|
||||||
|
sb.Remove(sb.Length - 2, 2).Append(");\r\n");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tboldname != null)
|
||||||
|
{
|
||||||
|
if (existsTable(tboldname) == false)
|
||||||
|
//旧表不存在
|
||||||
|
tboldname = null;
|
||||||
|
}
|
||||||
|
isexistsTb = existsTable(tbname);
|
||||||
|
if (isexistsTb == false)
|
||||||
|
{ //表不存在
|
||||||
|
if (tboldname == null)
|
||||||
|
{
|
||||||
|
createTable(tbname);
|
||||||
|
createTableIndex(tbname);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//如果新表,旧表不在一起,创建新表,导入数据,删除旧表
|
||||||
|
istmpatler = true;
|
||||||
|
}
|
||||||
|
if (tboldname != null && isexistsTb == true)
|
||||||
|
throw new Exception($"旧表(OldName):{tboldname} 存在,数据库已存在 {tbname} 表,无法改名");
|
||||||
|
|
||||||
|
DataTable schemaColumns = null;
|
||||||
|
DataTable schemaDataTypes = null;
|
||||||
|
DataTable schemaIndexes = null;
|
||||||
|
using (var conn = _orm.Ado.MasterPool.Get())
|
||||||
|
{
|
||||||
|
schemaColumns = conn.Value.GetSchema("COLUMNS");
|
||||||
|
schemaDataTypes = conn.Value.GetSchema("DATATYPES");
|
||||||
|
schemaIndexes = conn.Value.GetSchema("INDEXES");
|
||||||
|
}
|
||||||
|
Func<string, string, bool> checkPrimaryKeyByTableNameAndColumn = (tn, cn) =>
|
||||||
|
{
|
||||||
|
int table_name_index = 0, primary_key_index = 0, column_name_index = 0;
|
||||||
|
for (var a = 0; a < schemaIndexes.Columns.Count; a++)
|
||||||
|
{
|
||||||
|
switch (schemaIndexes.Columns[a].ColumnName.ToLower())
|
||||||
|
{
|
||||||
|
case "table_name":
|
||||||
|
table_name_index = a;
|
||||||
|
break;
|
||||||
|
case "primary_key":
|
||||||
|
primary_key_index = a;
|
||||||
|
break;
|
||||||
|
case "column_name":
|
||||||
|
column_name_index = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (DataRow row in schemaIndexes.Rows)
|
||||||
|
{
|
||||||
|
if (string.Compare(row[table_name_index]?.ToString(), tn, true) != 0) continue;
|
||||||
|
if (string.Compare(row[column_name_index]?.ToString(), cn, true) != 0) continue;
|
||||||
|
return new[] { "1", "True", "true", "t", "yes", "ok" }.Contains(row[primary_key_index]?.ToString());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
Func<string, List<string[]>> getIndexesByTableName = tn =>
|
||||||
|
{
|
||||||
|
int table_name_index = 0, index_name_index = 0, primary_key_index = 0, unique_index = 0, column_name_index = 0, collation_index = 0;
|
||||||
|
for (var a = 0; a < schemaIndexes.Columns.Count; a++)
|
||||||
|
{
|
||||||
|
switch (schemaIndexes.Columns[a].ColumnName.ToLower())
|
||||||
|
{
|
||||||
|
case "table_name":
|
||||||
|
table_name_index = a;
|
||||||
|
break;
|
||||||
|
case "index_name":
|
||||||
|
index_name_index = a;
|
||||||
|
break;
|
||||||
|
case "primary_key":
|
||||||
|
primary_key_index = a;
|
||||||
|
break;
|
||||||
|
case "unique":
|
||||||
|
unique_index = a;
|
||||||
|
break;
|
||||||
|
case "column_name":
|
||||||
|
column_name_index = a;
|
||||||
|
break;
|
||||||
|
case "collation":
|
||||||
|
collation_index = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var idxs = new List<string[]>();
|
||||||
|
foreach (DataRow row in schemaIndexes.Rows)
|
||||||
|
{
|
||||||
|
if (string.Compare(row[table_name_index]?.ToString(), tn, true) != 0) continue;
|
||||||
|
if (new[] { "1", "True", "true", "t", "yes", "ok" }.Contains(row[primary_key_index]?.ToString())) continue;
|
||||||
|
var column_name = row[column_name_index]?.ToString();
|
||||||
|
var index_name = row[index_name_index]?.ToString();
|
||||||
|
var isDesc = int.TryParse(row[collation_index]?.ToString(), out var collation) ? (collation == 2) : false;
|
||||||
|
var unique = new[] { "1", "True", "true", "t", "yes", "ok" }.Contains(row[unique_index]?.ToString());
|
||||||
|
idxs.Add(new[] { column_name, index_name, isDesc ? "1" : "0", unique ? "1" : "0" });
|
||||||
|
}
|
||||||
|
return idxs;
|
||||||
|
};
|
||||||
|
Func<string, Dictionary<string, (string column, string sqlType, bool is_nullable, bool is_identity, string comment)>> getColumnsByTableName = tn =>
|
||||||
|
{
|
||||||
|
int table_name_index = 0, column_name_index = 0, is_nullable_index = 0, data_type_index = 0,
|
||||||
|
character_maximum_length_index = 0, character_octet_length_index = 0, numeric_precision_index = 0, numeric_scale_index = 0,
|
||||||
|
datetime_precision_index = 0, description_index = 0;
|
||||||
|
for (var a = 0; a < schemaColumns.Columns.Count; a++)
|
||||||
|
{
|
||||||
|
switch (schemaColumns.Columns[a].ColumnName.ToLower())
|
||||||
|
{
|
||||||
|
case "table_name":
|
||||||
|
table_name_index = a;
|
||||||
|
break;
|
||||||
|
case "column_name":
|
||||||
|
column_name_index = a;
|
||||||
|
break;
|
||||||
|
case "is_nullable":
|
||||||
|
is_nullable_index = a;
|
||||||
|
break;
|
||||||
|
case "data_type":
|
||||||
|
data_type_index = a;
|
||||||
|
break;
|
||||||
|
case "character_maximum_length":
|
||||||
|
character_maximum_length_index = a;
|
||||||
|
break;
|
||||||
|
case "character_octet_length":
|
||||||
|
character_octet_length_index = a;
|
||||||
|
break;
|
||||||
|
case "numeric_precision":
|
||||||
|
numeric_precision_index = a;
|
||||||
|
break;
|
||||||
|
case "numeric_scale":
|
||||||
|
numeric_scale_index = a;
|
||||||
|
break;
|
||||||
|
case "datetime_precision":
|
||||||
|
datetime_precision_index = a;
|
||||||
|
break;
|
||||||
|
case "description":
|
||||||
|
description_index = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int datatype_ProviderDbType_index = 0, datatype_NativeDataType_index = 0, datatype_TypeName_index = 0, datatype_IsAutoIncrementable_index = 0;
|
||||||
|
for (var a = 0; a < schemaDataTypes.Columns.Count; a++)
|
||||||
|
{
|
||||||
|
switch (schemaDataTypes.Columns[a].ColumnName.ToLower())
|
||||||
|
{
|
||||||
|
case "providerdbtype":
|
||||||
|
datatype_ProviderDbType_index = a;
|
||||||
|
break;
|
||||||
|
case "nativedatatype":
|
||||||
|
datatype_NativeDataType_index = a;
|
||||||
|
break;
|
||||||
|
case "typename":
|
||||||
|
datatype_TypeName_index = a;
|
||||||
|
break;
|
||||||
|
case "isautoincrementable":
|
||||||
|
datatype_IsAutoIncrementable_index = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Func<string, DataRow> getDataType = dtnum =>
|
||||||
|
{
|
||||||
|
DataRow dtRow = null; //这里的写法是为了照顾 SchemaTypes 返回的结构
|
||||||
|
foreach (DataRow dataType in schemaDataTypes.Rows)
|
||||||
|
{
|
||||||
|
if (datatype_ProviderDbType_index >= 0 && dataType[datatype_ProviderDbType_index]?.ToString() == dtnum) dtRow = dataType;
|
||||||
|
if (datatype_NativeDataType_index >= 0 && dataType[datatype_NativeDataType_index]?.ToString() == dtnum) dtRow = dataType;
|
||||||
|
}
|
||||||
|
return dtRow;
|
||||||
|
};
|
||||||
|
var ret = new Dictionary<string, (string column, string sqlType, bool is_nullable, bool is_identity, string comment)>();
|
||||||
|
foreach (DataRow row in schemaColumns.Rows)
|
||||||
|
{
|
||||||
|
if (string.Compare(row[table_name_index]?.ToString(), tn, true) != 0) continue;
|
||||||
|
var column_name = row[column_name_index]?.ToString();
|
||||||
|
var dataTypeRow = getDataType(row[data_type_index]?.ToString());
|
||||||
|
var is_identity = new[] { "1", "True", "true", "t", "yes", "ok" }.Contains(dataTypeRow[datatype_IsAutoIncrementable_index]?.ToString());
|
||||||
|
var is_nullable = new[] { "1", "True", "true", "t", "yes", "ok" }.Contains(row[is_nullable_index]?.ToString());
|
||||||
|
if (is_nullable && checkPrimaryKeyByTableNameAndColumn(tn, column_name)) is_nullable = false;
|
||||||
|
var comment = row[description_index]?.ToString();
|
||||||
|
if (string.IsNullOrEmpty(comment)) comment = null;
|
||||||
|
int.TryParse(row[character_maximum_length_index]?.ToString(), out var character_maximum_length);
|
||||||
|
int.TryParse(row[character_octet_length_index]?.ToString(), out var character_octet_length);
|
||||||
|
int.TryParse(row[numeric_precision_index]?.ToString(), out var numeric_precision);
|
||||||
|
int.TryParse(row[numeric_scale_index]?.ToString(), out var numeric_scale);
|
||||||
|
int.TryParse(row[datetime_precision_index]?.ToString(), out var datetime_precision);
|
||||||
|
var datatype = dataTypeRow[datatype_TypeName_index]?.ToString().ToUpper();
|
||||||
|
if (numeric_precision > 0 && numeric_scale > 0) datatype = $"{datatype}({numeric_precision},{numeric_scale})";
|
||||||
|
else if (character_maximum_length > 0 && character_octet_length > 0) datatype = $"{datatype}({character_maximum_length})";
|
||||||
|
ret.Add(column_name, (column_name, datatype, is_nullable, is_identity, comment));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
|
||||||
|
var tbtmp = tboldname ?? tbname;
|
||||||
|
var tbstruct = getColumnsByTableName(tbtmp);
|
||||||
|
|
||||||
|
if (istmpatler == false)
|
||||||
|
{
|
||||||
|
foreach (var tbcol in tb.ColumnsByPosition)
|
||||||
|
{
|
||||||
|
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL");
|
||||||
|
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||||
|
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||||
|
{
|
||||||
|
if (tbstructcol.sqlType != "LONG" && tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||||
|
istmpatler = true;
|
||||||
|
if (tbstructcol.sqlType != "BIT" && tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||||
|
istmpatler = true;
|
||||||
|
if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity)
|
||||||
|
istmpatler = true;
|
||||||
|
if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
|
||||||
|
//修改列名
|
||||||
|
istmpatler = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//添加列
|
||||||
|
istmpatler = true;
|
||||||
|
}
|
||||||
|
var dsuk = getIndexesByTableName(tbtmp);
|
||||||
|
foreach (var uk in tb.Indexes)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(uk.Name) || uk.Columns.Any() == false) continue;
|
||||||
|
var dsukfind1 = dsuk.Where(a => string.Compare(a[1], uk.Name, true) == 0).ToArray();
|
||||||
|
if (dsukfind1.Any() == false || dsukfind1.Length != uk.Columns.Length || dsukfind1.Where(a => (a[3] == "1") == uk.IsUnique && uk.Columns.Where(b => string.Compare(b.Column.Attribute.Name, a[0], true) == 0 && (a[2] == "1") == b.IsDesc).Any()).Count() != uk.Columns.Length)
|
||||||
|
istmpatler = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (istmpatler == false)
|
||||||
|
{
|
||||||
|
sb.Append(sbalter);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, bool> dicDropTable = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
Action<string> dropTable = tn => {
|
||||||
|
if (dicDropTable.ContainsKey(tn)) return;
|
||||||
|
dicDropTable.Add(tn, true);
|
||||||
|
sb.Append("DROP TABLE ").Append(_commonUtils.QuoteSqlName(tn)).Append(";\r\n");
|
||||||
|
};
|
||||||
|
Action<string, string> createTableImportData = (newtn, oldtn) =>
|
||||||
|
{
|
||||||
|
if (existsTable(newtn)) dropTable(newtn);
|
||||||
|
createTable(newtn);
|
||||||
|
sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(newtn)).Append(" (");
|
||||||
|
foreach (var tbcol in tb.ColumnsByPosition)
|
||||||
|
sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||||
|
sb.Remove(sb.Length - 2, 2).Append(")\r\nSELECT ");
|
||||||
|
foreach (var tbcol in tb.ColumnsByPosition)
|
||||||
|
{
|
||||||
|
var insertvalue = "NULL";
|
||||||
|
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||||
|
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||||
|
{
|
||||||
|
insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
|
||||||
|
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||||
|
{
|
||||||
|
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "");
|
||||||
|
insertvalue = MsAccessUtils.GetCastSql(insertvalue, tbcol.Attribute.MapType);
|
||||||
|
}
|
||||||
|
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||||
|
insertvalue = $"iif(isnull({insertvalue}),{tbcol.DbDefaultValue},{insertvalue})";
|
||||||
|
}
|
||||||
|
else if (tbcol.Attribute.IsNullable == false)
|
||||||
|
insertvalue = tbcol.DbDefaultValue;
|
||||||
|
sb.Append(insertvalue).Append(", ");
|
||||||
|
}
|
||||||
|
sb.Remove(sb.Length - 2, 2).Append(" FROM ").Append(_commonUtils.QuoteSqlName(oldtn)).Append(";\r\n");
|
||||||
|
dropTable(oldtn);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tboldname != null && isexistsTb == true)
|
||||||
|
{
|
||||||
|
createTableImportData(tbname + "_FreeSqlBackup", tbname); //备份 tbname 表
|
||||||
|
createTableImportData(tbname, tboldname); //创建新表,把 oldname 旧表数据导入到新表,删除 oldname
|
||||||
|
}
|
||||||
|
if (tboldname != null && isexistsTb == false)
|
||||||
|
{
|
||||||
|
createTableImportData(tbname, tboldname); //创建新表,把 oldname 旧表数据导入到新表,删除 oldname
|
||||||
|
}
|
||||||
|
if (tboldname == null && isexistsTb == true)
|
||||||
|
{
|
||||||
|
createTableImportData(tbname + "_FreeSqlTmp", tbname); //创建 Tmp 表,把 tbname 表数据导入到 Tmp,删除 tbname
|
||||||
|
createTableImportData(tbname, tbname + "_FreeSqlTmp"); //创建 新表,把 Tmp 表数据导入到新表,删除 Tmp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.Length == 0 ? null : sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int ExecuteDDLStatements(string ddl)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ddl)) return 0;
|
||||||
|
var scripts = ddl.Split(new string[] { ";\r\n" }, StringSplitOptions.None).Where(a => string.IsNullOrEmpty(a.Trim()) == false).ToArray();
|
||||||
|
|
||||||
|
if (scripts.Any() == false) return 0;
|
||||||
|
if (scripts.Length == 1) return base.ExecuteDDLStatements(ddl);
|
||||||
|
|
||||||
|
var affrows = 0;
|
||||||
|
foreach (var script in scripts)
|
||||||
|
affrows += base.ExecuteDDLStatements(script);
|
||||||
|
return affrows;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
398
Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs
Normal file
398
Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs
Normal file
@ -0,0 +1,398 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess
|
||||||
|
{
|
||||||
|
class MsAccessExpression : CommonExpression
|
||||||
|
{
|
||||||
|
|
||||||
|
public MsAccessExpression(CommonUtils common) : base(common) { }
|
||||||
|
|
||||||
|
public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||||
|
switch (exp.NodeType)
|
||||||
|
{
|
||||||
|
case ExpressionType.Convert:
|
||||||
|
var operandExp = (exp as UnaryExpression)?.Operand;
|
||||||
|
var gentype = exp.Type.NullableTypeOrThis();
|
||||||
|
if (gentype != operandExp.Type.NullableTypeOrThis())
|
||||||
|
{
|
||||||
|
var retBefore = getExp(operandExp);
|
||||||
|
var retAfter = MsAccessUtils.GetCastSql(retBefore, gentype);
|
||||||
|
if (retBefore != retAfter) return retAfter;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ExpressionType.Call:
|
||||||
|
var callExp = exp as MethodCallExpression;
|
||||||
|
|
||||||
|
switch (callExp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Parse":
|
||||||
|
case "TryParse":
|
||||||
|
var retBefore = getExp(callExp.Arguments[0]);
|
||||||
|
var retAfter = MsAccessUtils.GetCastSql(retBefore, callExp.Method.DeclaringType.NullableTypeOrThis());
|
||||||
|
if (retBefore != retAfter) return retAfter;
|
||||||
|
return null;
|
||||||
|
case "NewGuid":
|
||||||
|
switch (callExp.Method.DeclaringType.NullableTypeOrThis().ToString())
|
||||||
|
{
|
||||||
|
case "System.Guid": return $"newid()";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
case "Next":
|
||||||
|
if (callExp.Object?.Type == typeof(Random)) return "rnd*1000000000000000";
|
||||||
|
return null;
|
||||||
|
case "NextDouble":
|
||||||
|
if (callExp.Object?.Type == typeof(Random)) return "rnd";
|
||||||
|
return null;
|
||||||
|
case "Random":
|
||||||
|
if (callExp.Method.DeclaringType.IsNumberType()) return "rnd";
|
||||||
|
return null;
|
||||||
|
case "ToString":
|
||||||
|
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? MsAccessUtils.GetCastSql(getExp(callExp.Object), typeof(string)) : null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var objExp = callExp.Object;
|
||||||
|
var objType = objExp?.Type;
|
||||||
|
if (objType?.FullName == "System.Byte[]") return null;
|
||||||
|
|
||||||
|
var argIndex = 0;
|
||||||
|
if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable))
|
||||||
|
{
|
||||||
|
objExp = callExp.Arguments.FirstOrDefault();
|
||||||
|
objType = objExp?.Type;
|
||||||
|
argIndex++;
|
||||||
|
}
|
||||||
|
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||||
|
if (objType != null || objType.IsArrayOrList())
|
||||||
|
{
|
||||||
|
tsc.SetMapColumnTmp(null);
|
||||||
|
var args1 = getExp(callExp.Arguments[argIndex]);
|
||||||
|
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
|
||||||
|
var oldDbParams = tsc.SetDbParamsReturnOld(null);
|
||||||
|
var left = objExp == null ? null : getExp(objExp);
|
||||||
|
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
|
||||||
|
tsc.SetDbParamsReturnOld(oldDbParams);
|
||||||
|
switch (callExp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Contains":
|
||||||
|
//判断 in //在各大 Provider AdoProvider 中已约定,500元素分割, 3空格\r\n4空格
|
||||||
|
return $"(({args1}) in {left.Replace(", \r\n \r\n", $") \r\n OR ({args1}) in (")})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ExpressionType.NewArrayInit:
|
||||||
|
var arrExp = exp as NewArrayExpression;
|
||||||
|
var arrSb = new StringBuilder();
|
||||||
|
arrSb.Append("(");
|
||||||
|
for (var a = 0; a < arrExp.Expressions.Count; a++)
|
||||||
|
{
|
||||||
|
if (a > 0) arrSb.Append(",");
|
||||||
|
arrSb.Append(getExp(arrExp.Expressions[a]));
|
||||||
|
}
|
||||||
|
if (arrSb.Length == 1) arrSb.Append("NULL");
|
||||||
|
return arrSb.Append(")").ToString();
|
||||||
|
case ExpressionType.ListInit:
|
||||||
|
var listExp = exp as ListInitExpression;
|
||||||
|
var listSb = new StringBuilder();
|
||||||
|
listSb.Append("(");
|
||||||
|
for (var a = 0; a < listExp.Initializers.Count; a++)
|
||||||
|
{
|
||||||
|
if (listExp.Initializers[a].Arguments.Any() == false) continue;
|
||||||
|
if (a > 0) listSb.Append(",");
|
||||||
|
listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
|
||||||
|
}
|
||||||
|
if (listSb.Length == 1) listSb.Append("NULL");
|
||||||
|
return listSb.Append(")").ToString();
|
||||||
|
case ExpressionType.New:
|
||||||
|
var newExp = exp as NewExpression;
|
||||||
|
if (typeof(IList).IsAssignableFrom(newExp.Type))
|
||||||
|
{
|
||||||
|
if (newExp.Arguments.Count == 0) return "(NULL)";
|
||||||
|
if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
|
||||||
|
return getExp(newExp.Arguments[0]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ExpressionLambdaToSqlMemberAccessString(MemberExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
if (exp.Expression == null)
|
||||||
|
{
|
||||||
|
switch (exp.Member.Name)
|
||||||
|
{
|
||||||
|
case "Empty": return "''";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var left = ExpressionLambdaToSql(exp.Expression, tsc);
|
||||||
|
switch (exp.Member.Name)
|
||||||
|
{
|
||||||
|
case "Length": return $"len({left})";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override string ExpressionLambdaToSqlMemberAccessDateTime(MemberExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
if (exp.Expression == null)
|
||||||
|
{
|
||||||
|
switch (exp.Member.Name)
|
||||||
|
{
|
||||||
|
case "Now": return _common.Now;
|
||||||
|
case "UtcNow": return _common.NowUtc;
|
||||||
|
case "Today": return "date";
|
||||||
|
case "MinValue": return "'1753/1/1 0:00:00'";
|
||||||
|
case "MaxValue": return "'9999/12/31 23:59:59'";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var left = ExpressionLambdaToSql(exp.Expression, tsc);
|
||||||
|
switch (exp.Member.Name)
|
||||||
|
{
|
||||||
|
case "Date": return $"format({left},'yyyy-mm-dd')";
|
||||||
|
case "TimeOfDay": return $"datediff('s', format({left},'yyyy-mm-dd'), {left})";
|
||||||
|
case "DayOfWeek": return $"(format({left},'w')-1)";
|
||||||
|
case "Day": return $"day({left})";
|
||||||
|
case "DayOfYear": return $"format({left},'y')";
|
||||||
|
case "Month": return $"month({left})";
|
||||||
|
case "Year": return $"year({left})";
|
||||||
|
case "Hour": return $"hour({left})";
|
||||||
|
case "Minute": return $"minute({left})";
|
||||||
|
case "Second": return $"second({left})";
|
||||||
|
case "Millisecond": return $"(second({left})/1000)";
|
||||||
|
case "Ticks": return $"({MsAccessUtils.GetCastSql($"datediff('s', '1970-1-1', {left})", typeof(long))}*10000000+621355968000000000)";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override string ExpressionLambdaToSqlMemberAccessTimeSpan(MemberExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
if (exp.Expression == null)
|
||||||
|
{
|
||||||
|
switch (exp.Member.Name)
|
||||||
|
{
|
||||||
|
case "Zero": return "0";
|
||||||
|
case "MinValue": return "-922337203685477580"; //微秒 Ticks / 10
|
||||||
|
case "MaxValue": return "922337203685477580";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var left = ExpressionLambdaToSql(exp.Expression, tsc);
|
||||||
|
switch (exp.Member.Name)
|
||||||
|
{
|
||||||
|
case "Days": return $"clng(({left})/{60 * 60 * 24}+1)";
|
||||||
|
case "Hours": return $"clng(({left})/{60 * 60} mod 24+1)";
|
||||||
|
case "Milliseconds": return $"({MsAccessUtils.GetCastSql(left, typeof(long))}*1000)";
|
||||||
|
case "Minutes": return $"clng(({left})/60 mod 60+1)";
|
||||||
|
case "Seconds": return $"(({left}) mod 60)";
|
||||||
|
case "Ticks": return $"({MsAccessUtils.GetCastSql(left, typeof(long))}*10000000)";
|
||||||
|
case "TotalDays": return $"(({left})/{60 * 60 * 24})";
|
||||||
|
case "TotalHours": return $"(({left})/{60 * 60})";
|
||||||
|
case "TotalMilliseconds": return $"({MsAccessUtils.GetCastSql(left, typeof(long))}*1000)";
|
||||||
|
case "TotalMinutes": return $"(({left})/60)";
|
||||||
|
case "TotalSeconds": return $"({left})";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||||
|
if (exp.Object == null)
|
||||||
|
{
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "IsNullOrEmpty":
|
||||||
|
var arg1 = getExp(exp.Arguments[0]);
|
||||||
|
return $"({arg1} is null or {arg1} = '')";
|
||||||
|
case "IsNullOrWhiteSpace":
|
||||||
|
var arg2 = getExp(exp.Arguments[0]);
|
||||||
|
return $"({arg2} is null or {arg2} = '' or ltrim({arg2}) = '')";
|
||||||
|
case "Concat":
|
||||||
|
return _common.StringConcat(exp.Arguments.Select(a => getExp(a)).ToArray(), exp.Arguments.Select(a => a.Type).ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var left = getExp(exp.Object);
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "StartsWith":
|
||||||
|
case "EndsWith":
|
||||||
|
case "Contains":
|
||||||
|
var args0Value = getExp(exp.Arguments[0]);
|
||||||
|
if (args0Value == "NULL") return $"({left}) IS NULL";
|
||||||
|
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value}+'%')")}";
|
||||||
|
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+{args0Value})")}";
|
||||||
|
if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}";
|
||||||
|
return $"({left}) LIKE ('%'+{args0Value}+'%')";
|
||||||
|
case "ToLower": return $"lcase({left})";
|
||||||
|
case "ToUpper": return $"ucase({left})";
|
||||||
|
case "Substring":
|
||||||
|
var substrArgs1 = getExp(exp.Arguments[0]);
|
||||||
|
if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString();
|
||||||
|
else substrArgs1 += "+1";
|
||||||
|
if (exp.Arguments.Count == 1) return $"left({left}, {substrArgs1})";
|
||||||
|
return $"mid({left}, {substrArgs1}, {getExp(exp.Arguments[1])})";
|
||||||
|
case "IndexOf":
|
||||||
|
var indexOfFindStr = getExp(exp.Arguments[0]);
|
||||||
|
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32")
|
||||||
|
{
|
||||||
|
var locateArgs1 = getExp(exp.Arguments[1]);
|
||||||
|
if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString();
|
||||||
|
else locateArgs1 += "+1";
|
||||||
|
return $"(instr({locateArgs1}, {left}, {indexOfFindStr})-1)";
|
||||||
|
}
|
||||||
|
return $"(instr({left}, {indexOfFindStr})-1)";
|
||||||
|
case "PadLeft":
|
||||||
|
if (exp.Arguments.Count == 1) return $"lpad({left}, {getExp(exp.Arguments[0])})";
|
||||||
|
return $"lpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
|
case "PadRight":
|
||||||
|
if (exp.Arguments.Count == 1) return $"rpad({left}, {getExp(exp.Arguments[0])})";
|
||||||
|
return $"rpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
|
case "Trim": return $"ltrim(rtrim({left}))";
|
||||||
|
case "TrimStart": return $"ltrim({left})";
|
||||||
|
case "TrimEnd": return $"rtrim({left})";
|
||||||
|
case "Replace": return $"replace({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
|
case "CompareTo": return $"strcomp({left}, {getExp(exp.Arguments[0])})";
|
||||||
|
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Abs": return $"abs({getExp(exp.Arguments[0])})";
|
||||||
|
case "Sign": return $"sign({getExp(exp.Arguments[0])})";
|
||||||
|
case "Floor": return $"clng({getExp(exp.Arguments[0])}+1)";
|
||||||
|
case "Ceiling": return $"clng({getExp(exp.Arguments[0])})";
|
||||||
|
case "Round":
|
||||||
|
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") return $"round({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
|
return $"round({getExp(exp.Arguments[0])}, 0)";
|
||||||
|
case "Exp": return $"exp({getExp(exp.Arguments[0])})";
|
||||||
|
case "Log": return $"log({getExp(exp.Arguments[0])})";
|
||||||
|
case "Log10": return $"log10({getExp(exp.Arguments[0])})";
|
||||||
|
case "Pow": return $"pow({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
|
case "Sqrt": return $"sqr({getExp(exp.Arguments[0])})";
|
||||||
|
case "Cos": return $"cos({getExp(exp.Arguments[0])})";
|
||||||
|
case "Sin": return $"sin({getExp(exp.Arguments[0])})";
|
||||||
|
case "Tan": return $"tan({getExp(exp.Arguments[0])})";
|
||||||
|
case "Acos": return $"acos({getExp(exp.Arguments[0])})";
|
||||||
|
case "Asin": return $"asin({getExp(exp.Arguments[0])})";
|
||||||
|
case "Atan": return $"atan({getExp(exp.Arguments[0])})";
|
||||||
|
case "Atan2": return $"atan2({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
|
case "Truncate": return $"floor({getExp(exp.Arguments[0])})";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||||
|
if (exp.Object == null)
|
||||||
|
{
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Compare": return $"({getExp(exp.Arguments[0])} - ({getExp(exp.Arguments[1])}))";
|
||||||
|
case "DaysInMonth": return $"format(dateadd('d', -1, dateadd('m', 1, {MsAccessUtils.GetCastSql(getExp(exp.Arguments[0]), typeof(string))} + '-' + {MsAccessUtils.GetCastSql(getExp(exp.Arguments[1]), typeof(string))} + '-1')),'d')";
|
||||||
|
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
||||||
|
|
||||||
|
case "IsLeapYear":
|
||||||
|
var isLeapYearArgs1 = getExp(exp.Arguments[0]);
|
||||||
|
return $"(({isLeapYearArgs1}) mod 4=0 AND ({isLeapYearArgs1}) mod 100<>0 OR ({isLeapYearArgs1}) mod 400=0)";
|
||||||
|
|
||||||
|
case "Parse": return MsAccessUtils.GetCastSql(getExp(exp.Arguments[0]), typeof(DateTime));
|
||||||
|
case "ParseExact":
|
||||||
|
case "TryParse":
|
||||||
|
case "TryParseExact": return MsAccessUtils.GetCastSql(getExp(exp.Arguments[0]), typeof(DateTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var left = getExp(exp.Object);
|
||||||
|
var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]);
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Add": return $"dateadd('s', {args1}, {left})";
|
||||||
|
case "AddDays": return $"dateadd('d', {args1}, {left})";
|
||||||
|
case "AddHours": return $"dateadd('h', {args1}, {left})";
|
||||||
|
case "AddMilliseconds": return $"dateadd('s', ({args1})/1000, {left})";
|
||||||
|
case "AddMinutes": return $"dateadd('n', {args1}, {left})";
|
||||||
|
case "AddMonths": return $"dateadd('m', {args1}, {left})";
|
||||||
|
case "AddSeconds": return $"dateadd('s', {args1}, {left})";
|
||||||
|
case "AddTicks": return $"dateadd('s', ({args1})/10000000, {left})";
|
||||||
|
case "AddYears": return $"dateadd('yyyy', {args1}, {left})";
|
||||||
|
case "Subtract":
|
||||||
|
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName)
|
||||||
|
{
|
||||||
|
case "System.DateTime": return $"datediff('s', {args1}, {left})";
|
||||||
|
case "System.TimeSpan": return $"dateadd('s', ({args1})*-1, {left})";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Equals": return $"({left} = {args1})";
|
||||||
|
case "CompareTo": return $"datediff('s',{args1},{left})";
|
||||||
|
case "ToString": return exp.Arguments.Count == 0 ? $"format({left},'yyyy-mm-dd HH:mm:ss')" : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||||
|
if (exp.Object == null)
|
||||||
|
{
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Compare": return $"({getExp(exp.Arguments[0])}-({getExp(exp.Arguments[1])}))";
|
||||||
|
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
||||||
|
case "FromDays": return $"(({getExp(exp.Arguments[0])})*{60 * 60 * 24})";
|
||||||
|
case "FromHours": return $"(({getExp(exp.Arguments[0])})*{60 * 60})";
|
||||||
|
case "FromMilliseconds": return $"(({getExp(exp.Arguments[0])})/1000)";
|
||||||
|
case "FromMinutes": return $"(({getExp(exp.Arguments[0])})*60)";
|
||||||
|
case "FromSeconds": return $"({getExp(exp.Arguments[0])})";
|
||||||
|
case "FromTicks": return $"(({getExp(exp.Arguments[0])})/10000000)";
|
||||||
|
case "Parse": return MsAccessUtils.GetCastSql(getExp(exp.Arguments[0]), typeof(long));
|
||||||
|
case "ParseExact":
|
||||||
|
case "TryParse":
|
||||||
|
case "TryParseExact": return MsAccessUtils.GetCastSql(getExp(exp.Arguments[0]), typeof(long));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var left = getExp(exp.Object);
|
||||||
|
var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]);
|
||||||
|
switch (exp.Method.Name)
|
||||||
|
{
|
||||||
|
case "Add": return $"({left}+{args1})";
|
||||||
|
case "Subtract": return $"({left}-({args1}))";
|
||||||
|
case "Equals": return $"({left} = {args1})";
|
||||||
|
case "CompareTo": return $"({left}-({args1}))";
|
||||||
|
case "ToString": return MsAccessUtils.GetCastSql(left, typeof(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, ExpTSC tsc)
|
||||||
|
{
|
||||||
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||||
|
if (exp.Object == null && exp.Method.DeclaringType == typeof(Convert))
|
||||||
|
{
|
||||||
|
var retBefore = getExp(exp.Arguments[0]);
|
||||||
|
var retAfter = MsAccessUtils.GetCastSql(retBefore, exp.Method.ReturnType.NullableTypeOrThis());
|
||||||
|
if (retBefore != retAfter) return retAfter;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Providers/FreeSql.Provider.MsAccess/MsAccessProvider.cs
Normal file
60
Providers/FreeSql.Provider.MsAccess/MsAccessProvider.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using FreeSql.MsAccess.Curd;
|
||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.CommonProvider;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess
|
||||||
|
{
|
||||||
|
|
||||||
|
public class MsAccessProvider<TMark> : IFreeSql<TMark>
|
||||||
|
{
|
||||||
|
|
||||||
|
public ISelect<T1> Select<T1>() where T1 : class => new MsAccessSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
|
||||||
|
public ISelect<T1> Select<T1>(object dywhere) where T1 : class => new MsAccessSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||||
|
public IInsert<T1> Insert<T1>() where T1 : class => new MsAccessInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||||
|
public IInsert<T1> Insert<T1>(T1 source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||||
|
public IInsert<T1> Insert<T1>(T1[] source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||||
|
public IInsert<T1> Insert<T1>(List<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||||
|
public IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||||
|
public IUpdate<T1> Update<T1>() where T1 : class => new MsAccessUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
|
||||||
|
public IUpdate<T1> Update<T1>(object dywhere) where T1 : class => new MsAccessUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||||
|
public IDelete<T1> Delete<T1>() where T1 : class => new MsAccessDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
|
||||||
|
public IDelete<T1> Delete<T1>(object dywhere) where T1 : class => new MsAccessDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||||
|
|
||||||
|
public IAdo Ado { get; }
|
||||||
|
public IAop Aop { get; }
|
||||||
|
public ICodeFirst CodeFirst { get; }
|
||||||
|
public IDbFirst DbFirst => throw new NotImplementedException("FreeSql.Provider.Sqlite 未实现该功能");
|
||||||
|
public MsAccessProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||||
|
{
|
||||||
|
this.InternalCommonUtils = new MsAccessUtils(this);
|
||||||
|
this.InternalCommonExpression = new MsAccessExpression(this.InternalCommonUtils);
|
||||||
|
|
||||||
|
this.Ado = new MsAccessAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||||
|
this.Aop = new AopProvider();
|
||||||
|
|
||||||
|
this.CodeFirst = new MsAccessCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal CommonUtils InternalCommonUtils { get; }
|
||||||
|
internal CommonExpression InternalCommonExpression { get; }
|
||||||
|
|
||||||
|
public void Transaction(Action handler) => Ado.Transaction(handler);
|
||||||
|
public void Transaction(TimeSpan timeout, Action handler) => Ado.Transaction(timeout, handler);
|
||||||
|
public void Transaction(IsolationLevel isolationLevel, TimeSpan timeout, Action handler) => Ado.Transaction(isolationLevel, timeout, handler);
|
||||||
|
|
||||||
|
public GlobalFilter GlobalFilter { get; } = new GlobalFilter();
|
||||||
|
|
||||||
|
~MsAccessProvider() => this.Dispose();
|
||||||
|
int _disposeCounter;
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
|
||||||
|
(this.Ado as AdoProvider)?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
126
Providers/FreeSql.Provider.MsAccess/MsAccessUtils.cs
Normal file
126
Providers/FreeSql.Provider.MsAccess/MsAccessUtils.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace FreeSql.MsAccess
|
||||||
|
{
|
||||||
|
|
||||||
|
public class MsAccessUtils : CommonUtils
|
||||||
|
{
|
||||||
|
public MsAccessUtils(IFreeSql orm) : base(orm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||||
|
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||||
|
var ret = new OleDbParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||||
|
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||||
|
if (tp != null) ret.OleDbType = (OleDbType)tp.Value;
|
||||||
|
_params?.Add(ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override DbParameter[] GetDbParamtersByObject(string sql, object obj) =>
|
||||||
|
Utils.GetDbParamtersByObject<OleDbParameter>(sql, obj, null, (name, type, value) =>
|
||||||
|
{
|
||||||
|
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||||
|
var ret = new OleDbParameter { ParameterName = $"@{name}", Value = value };
|
||||||
|
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||||
|
if (tp != null) ret.OleDbType = (OleDbType)tp.Value;
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
|
||||||
|
public override string FormatSql(string sql, params object[] args) => sql?.FormatAccess(args);
|
||||||
|
public override string QuoteSqlName(string name)
|
||||||
|
{
|
||||||
|
var nametrim = name.Trim();
|
||||||
|
if (nametrim.StartsWith("(") && nametrim.EndsWith(")"))
|
||||||
|
return nametrim; //原生SQL
|
||||||
|
return $"[{nametrim.TrimStart('[').TrimEnd(']').Replace(".", "].[")}]";
|
||||||
|
}
|
||||||
|
public override string TrimQuoteSqlName(string name)
|
||||||
|
{
|
||||||
|
var nametrim = name.Trim();
|
||||||
|
if (nametrim.StartsWith("(") && nametrim.EndsWith(")"))
|
||||||
|
return nametrim; //原生SQL
|
||||||
|
return $"{nametrim.TrimStart('[').TrimEnd(']').Replace("].[", ".").Replace(".[", ".")}";
|
||||||
|
}
|
||||||
|
public override string QuoteParamterName(string name) => $"@{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
|
||||||
|
public override string IsNull(string sql, object value) => $"iif(isnull({sql}), {value}, {sql})";
|
||||||
|
public override string StringConcat(string[] objs, Type[] types)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
var news = new string[objs.Length];
|
||||||
|
for (var a = 0; a < objs.Length; a++)
|
||||||
|
{
|
||||||
|
if (types[a] == typeof(string)) news[a] = objs[a];
|
||||||
|
else news[a] = MsAccessUtils.GetCastSql(objs[a], typeof(string));
|
||||||
|
}
|
||||||
|
return string.Join(" + ", news);
|
||||||
|
}
|
||||||
|
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} mod {right}";
|
||||||
|
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} / {right}";
|
||||||
|
public override string Now => "now()";
|
||||||
|
public override string NowUtc => "now()";
|
||||||
|
|
||||||
|
public override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
||||||
|
public override string QuoteReadColumn(Type type, string columnName) => columnName;
|
||||||
|
public override string FieldAsAlias(string alias) => $" as {alias}";
|
||||||
|
public override string IIF(string test, string ifTrue, string ifElse) => $"iif({test}, {ifTrue}, {ifElse})";
|
||||||
|
|
||||||
|
public override string GetNoneParamaterSqlValue(List<DbParameter> specialParams, Type type, object value)
|
||||||
|
{
|
||||||
|
if (value == null) return "NULL";
|
||||||
|
if (type == typeof(byte[]))
|
||||||
|
{
|
||||||
|
var bytes = value as byte[];
|
||||||
|
var sb = new StringBuilder().Append("0x");
|
||||||
|
foreach (var vc in bytes)
|
||||||
|
{
|
||||||
|
if (vc < 10) sb.Append("0");
|
||||||
|
sb.Append(vc.ToString("X"));
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
else if (type == typeof(TimeSpan) || type == typeof(TimeSpan?))
|
||||||
|
{
|
||||||
|
var ts = (TimeSpan)value;
|
||||||
|
value = $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}";
|
||||||
|
}
|
||||||
|
return FormatSql("{0}", value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetCastSql(string sqlExp, Type toType)
|
||||||
|
{
|
||||||
|
switch (toType.ToString())
|
||||||
|
{
|
||||||
|
case "System.Boolean": return $"(cstr({sqlExp}) not in ('0','false'))";
|
||||||
|
case "System.Byte": return $"cbyte({sqlExp})";
|
||||||
|
case "System.Char": return $"left(cstr({sqlExp}),1)";
|
||||||
|
case "System.DateTime": return $"cdate({sqlExp})";
|
||||||
|
case "System.Decimal": return $"ccur({sqlExp})";
|
||||||
|
case "System.Double": return $"cdbl({sqlExp})";
|
||||||
|
case "System.Int16": return $"cint({sqlExp})";
|
||||||
|
case "System.Int32": return $"cint({sqlExp})";
|
||||||
|
case "System.Int64": return $"clng({sqlExp})";
|
||||||
|
case "System.SByte": return $"cint({sqlExp})";
|
||||||
|
case "System.Single": return $"csng({sqlExp})";
|
||||||
|
case "System.String": return $"cstr({sqlExp})";
|
||||||
|
case "System.UInt16": return $"cint({sqlExp})";
|
||||||
|
case "System.UInt32": return $"clng({sqlExp})";
|
||||||
|
case "System.UInt64": return $"clng({sqlExp})";
|
||||||
|
case "System.Guid": return $"cstr({sqlExp})";
|
||||||
|
}
|
||||||
|
return sqlExp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,6 @@ namespace FreeSql.MySql
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -32,7 +32,6 @@ namespace FreeSql.Odbc.Dameng
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -34,7 +34,6 @@ namespace FreeSql.Odbc.Default
|
|||||||
}
|
}
|
||||||
OdbcAdapter Adapter => (_util == null ? FreeSqlOdbcGlobalExtensions.DefaultOdbcAdapter : _util._orm.GetOdbcAdapter());
|
OdbcAdapter Adapter => (_util == null ? FreeSqlOdbcGlobalExtensions.DefaultOdbcAdapter : _util._orm.GetOdbcAdapter());
|
||||||
|
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -34,7 +34,6 @@ namespace FreeSql.Odbc.GBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -33,7 +33,6 @@ namespace FreeSql.Odbc.MySql
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -32,7 +32,6 @@ namespace FreeSql.Odbc.Oracle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -34,7 +34,6 @@ namespace FreeSql.Odbc.PostgreSQL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -34,7 +34,6 @@ namespace FreeSql.Odbc.SqlServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
string[] ncharDbTypes = new[] { "NVARCHAR", "NCHAR", "NTEXT" };
|
string[] ncharDbTypes = new[] { "NVARCHAR", "NCHAR", "NTEXT" };
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,6 @@ namespace FreeSql.Oracle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -35,7 +35,6 @@ namespace FreeSql.PostgreSQL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -31,7 +31,6 @@ namespace FreeSql.Sqlite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
|
||||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||||
{
|
{
|
||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
|
@ -216,7 +216,7 @@ namespace FreeSql.Sqlite
|
|||||||
{
|
{
|
||||||
var dbcolumnName = string.Concat(dbcolumn[2]);
|
var dbcolumnName = string.Concat(dbcolumn[2]);
|
||||||
var isDesc = dbIndexesSql.IndexOf($@"{dbcolumnName}"" DESC", StringComparison.CurrentCultureIgnoreCase) == -1 ? "0" : "1";
|
var isDesc = dbIndexesSql.IndexOf($@"{dbcolumnName}"" DESC", StringComparison.CurrentCultureIgnoreCase) == -1 ? "0" : "1";
|
||||||
dsuk.Add(new[] { dbcolumnName, string.Concat(dbIndex[1]), isDesc, string.Concat(dbIndex[2]) }); ;
|
dsuk.Add(new[] { dbcolumnName, string.Concat(dbIndex[1]), isDesc, string.Concat(dbIndex[2]) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var uk in tb.Indexes)
|
foreach (var uk in tb.Indexes)
|
||||||
@ -238,7 +238,6 @@ namespace FreeSql.Sqlite
|
|||||||
var tablenameOnlyTb = tboldname == null ? _commonUtils.QuoteSqlName(tbname[1]) : _commonUtils.QuoteSqlName(tboldname[1]);
|
var tablenameOnlyTb = tboldname == null ? _commonUtils.QuoteSqlName(tbname[1]) : _commonUtils.QuoteSqlName(tboldname[1]);
|
||||||
var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}._FreeSqlTmp_{tbname[1]}");
|
var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}._FreeSqlTmp_{tbname[1]}");
|
||||||
//创建临时表
|
//创建临时表
|
||||||
//创建表
|
|
||||||
isIndent = false;
|
isIndent = false;
|
||||||
sb.Append("CREATE TABLE IF NOT EXISTS ").Append(tmptablename).Append(" ( ");
|
sb.Append("CREATE TABLE IF NOT EXISTS ").Append(tmptablename).Append(" ( ");
|
||||||
foreach (var tbcol in tb.ColumnsByPosition)
|
foreach (var tbcol in tb.ColumnsByPosition)
|
||||||
|
@ -28,7 +28,7 @@ namespace FreeSql.Sqlite
|
|||||||
public IAdo Ado { get; }
|
public IAdo Ado { get; }
|
||||||
public IAop Aop { get; }
|
public IAop Aop { get; }
|
||||||
public ICodeFirst CodeFirst { get; }
|
public ICodeFirst CodeFirst { get; }
|
||||||
public IDbFirst DbFirst => null;
|
public IDbFirst DbFirst => throw new NotImplementedException("FreeSql.Provider.Sqlite 未实现该功能");
|
||||||
public SqliteProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
public SqliteProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||||
{
|
{
|
||||||
this.InternalCommonUtils = new SqliteUtils(this);
|
this.InternalCommonUtils = new SqliteUtils(this);
|
||||||
|
@ -16,7 +16,7 @@ FreeSql 是功能强大的对象关系映射技术(O/RM),支持 .NETCore 2.1+
|
|||||||
- [x] 支持 导航属性一对多、多对多贪婪加载,以及延时加载;
|
- [x] 支持 导航属性一对多、多对多贪婪加载,以及延时加载;
|
||||||
- [x] 支持 同步/异步数据库操作方法;
|
- [x] 支持 同步/异步数据库操作方法;
|
||||||
- [x] 支持 读写分离、分表分库,租户设计,过滤器,乐观锁;
|
- [x] 支持 读写分离、分表分库,租户设计,过滤器,乐观锁;
|
||||||
- [x] 支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite/达梦数据库;
|
- [x] 支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite/达梦数据库/Access;
|
||||||
|
|
||||||
| | |
|
| | |
|
||||||
| - | - |
|
| - | - |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user