Skip to content

Commit

Permalink
- 修复 Ado.Query 查询字段重复时报错;#162 #165 #161 - 增加 FreeSql.Provider.MsAcces…
Browse files Browse the repository at this point in the history
…s 支持 Access 数据库操作,已通过 2003/2007 版本测试;
  • Loading branch information
28810 authored and 28810 committed Dec 23, 2019
1 parent d5ed1c8 commit a92c279
Show file tree
Hide file tree
Showing 69 changed files with 10,380 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion FreeSql.DbContext/FreeSql.DbContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Version>0.12.21</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<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>
<PackageTags>FreeSql ORM DbContext</PackageTags>
<RepositoryType>git</RepositoryType>
Expand Down
7 changes: 7 additions & 0 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FreeSql.Repository/FreeSql.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
<Version>0.12.21</Version>
<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>
<PackageTags>FreeSql ORM Repository</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,83 @@ public void AsTable()
a.Id,
a.Clicks
});

var sqltmp12 = g.mysql.Select<WF_Task>()
.Where(t => t.IsFinished && (t.AuditorId == "1" || t.AuditorId == "1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3"))
.GroupBy(t => new { t.ProcessId, t.NodeId, t.NodeName })
.ToSql(t => new WF_TaskGroupBy
{
TaskId = t.Max(t.Value.Id),
TaskType = t.Max(t.Value.Type),
ProcessId = t.Key.ProcessId,
NodeId = t.Key.NodeId,
NodeName = t.Key.NodeName
}, FieldAliasOptions.AsProperty);

var groupsql12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => type == typeof(WF_TaskGroupBy) ? $"( {sqltmp12} )" : null)
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToSql((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});

Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
LEFT JOIN `WF_ProcessInstance` b ON b.`Id` = a.`ProcessId`
WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql12);

var grouplist12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => $"( {sqltmp12} )")
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToList((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
}

[Table(DisableSyncStructure = true)]
class WF_TaskGroupBy
{
public int TaskId { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
}
class WF_Task
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int Type { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
public string AuditorId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
}
class WF_ProcessInstance
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
public bool EnabledMark { get; set; }
}

public class TestInclude_OneToManyModel1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,83 @@ public void AsTable()
a.Id,
a.Clicks
});

var sqltmp12 = g.mysql.Select<WF_Task>()
.Where(t => t.IsFinished && (t.AuditorId == "1" || t.AuditorId == "1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3"))
.GroupBy(t => new { t.ProcessId, t.NodeId, t.NodeName })
.ToSql(t => new WF_TaskGroupBy
{
TaskId = t.Max(t.Value.Id),
TaskType = t.Max(t.Value.Type),
ProcessId = t.Key.ProcessId,
NodeId = t.Key.NodeId,
NodeName = t.Key.NodeName
}, FieldAliasOptions.AsProperty);

var groupsql12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => type == typeof(WF_TaskGroupBy) ? $"( {sqltmp12} )" : null)
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToSql((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});

Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId` ProcessId, a.`NodeId` NodeId, a.`NodeName` NodeName
FROM `WF_Task` a
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
LEFT JOIN `WF_ProcessInstance` b ON b.`Id` = a.`ProcessId`
WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql12);

var grouplist12 = g.mysql.Select<WF_TaskGroupBy, WF_ProcessInstance>()
.AsTable((type, old) => $"( {sqltmp12} )")
.LeftJoin((a, p) => p.Id == a.ProcessId)
.Where((a, p) => (p.IsFinished || a.TaskType == 3) && p.EnabledMark)
.ToList((a, p) => new
{
WF_Task = a,
WF_ProcessInstance = p
});
}

[Table(DisableSyncStructure = true)]
class WF_TaskGroupBy
{
public int TaskId { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
}
class WF_Task
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int Type { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public string NodeName { get; set; }
public string AuditorId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
}
class WF_ProcessInstance
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public int TaskType { get; set; }
public int ProcessId { get; set; }
public int NodeId { get; set; }
public DateTime CreateTime { get; set; }
public bool IsFinished { get; set; }
public bool EnabledMark { get; set; }
}

public class TestInclude_OneToManyModel1
Expand Down
1 change: 1 addition & 0 deletions FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MsAccess\FreeSql.Provider.MsAccess.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySql\FreeSql.Provider.MySql.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
Expand Down
93 changes: 93 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessDeleteTest.cs
Original file line number Diff line number Diff line change
@@ -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>(); //��������

[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);
}
}
}
Loading

0 comments on commit a92c279

Please sign in to comment.