Skip to content

Commit

Permalink
- 增加 神州通用 ShenTong 实现;#325
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Jun 9, 2020
1 parent 7cd7e66 commit 49aa899
Show file tree
Hide file tree
Showing 51 changed files with 11,714 additions and 22 deletions.
1 change: 1 addition & 0 deletions FreeSql.DbContext/DbSet/DbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ bool CanAdd(TEntity data, bool isThrow)
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
return true;
default:
if (_tableIdentitys.Length == 1 && _table.Primarys.Length == 1)
Expand Down
2 changes: 2 additions & 0 deletions FreeSql.DbContext/DbSet/DbSetAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async Task AddPrivAsync(TEntity data, bool isCheck)
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
if (_tableIdentitys.Length == 1 && _table.Primarys.Length == 1)
{
await DbContextFlushCommandAsync();
Expand Down Expand Up @@ -104,6 +105,7 @@ async public Task AddRangeAsync(IEnumerable<TEntity> data)
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
await DbContextFlushCommandAsync();
var rets = await this.OrmInsert(data).ExecuteInsertedAsync();
if (rets.Count != data.Count()) throw new Exception($"特别错误:批量添加失败,{_db.OrmOriginal.Ado.DataType} 的返回数据,与添加的数目不匹配");
Expand Down
2 changes: 2 additions & 0 deletions FreeSql.DbContext/DbSet/DbSetSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void AddPriv(TEntity data, bool isCheck)
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
if (_tableIdentitys.Length == 1)
{
DbContextFlushCommand();
Expand Down Expand Up @@ -107,6 +108,7 @@ public void AddRange(IEnumerable<TEntity> data)
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
DbContextFlushCommand();
var rets = this.OrmInsert(data).ExecuteInserted();
if (rets.Count != data.Count()) throw new Exception($"特别错误:批量添加失败,{_db.OrmOriginal.Ado.DataType} 的返回数据,与添加的数目不匹配");
Expand Down
16 changes: 0 additions & 16 deletions FreeSql.DbContext/FreeSql.DbContext.xml

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

7 changes: 7 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<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" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.ShenTong\FreeSql.Provider.ShenTong.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Sqlite\FreeSql.Provider.Sqlite.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.SqlServer\FreeSql.Provider.SqlServer.csproj" />
</ItemGroup>
Expand All @@ -47,6 +48,12 @@
<Reference Include="DmProvider">
<HintPath>..\..\Providers\FreeSql.Provider.Dameng\lib\DmProvider\netstandard2.0\DmProvider.dll</HintPath>
</Reference>
<Reference Include="System.Data.OscarClient">
<HintPath>..\..\Providers\FreeSql.Provider.ShenTong\lib\System.Data.OscarClient.dll</HintPath>
</Reference>
<Reference Include="Mono.Security">
<HintPath>..\..\Providers\FreeSql.Provider.ShenTong\lib\Mono.Security.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
105 changes: 105 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/ShenTong/Curd/ShenTongDeleteTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace FreeSql.Tests.ShenTong
{
public class ShenTongDeleteTest
{

IDelete<Topic> delete => g.shentong.Delete<Topic>();

[Table(Name = "tb_topic_del")]
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.shentong.Delete<Topic>().ToSql());
var sql = g.shentong.Delete<Topic>(new[] { 1, 2 }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC_DEL\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);

sql = g.shentong.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC_DEL\" WHERE (\"ID\" = 1)", sql);

sql = g.shentong.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC_DEL\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);

sql = g.shentong.Delete<Topic>(new { id = 1 }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC_DEL\" WHERE (\"ID\" = 1)", sql);

sql = g.shentong.Delete<MultiPkTopic>(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql();
Assert.Equal("DELETE FROM \"MULTIPKTOPIC\" WHERE (\"ID1\" = 1 AND \"ID2\" = 10 OR \"ID1\" = 2 AND \"ID2\" = 20)", sql);
}
class MultiPkTopic
{
[Column(IsPrimary = true)]
public int Id1 { get; set; }
[Column(IsPrimary = true)]
public int Id2 { get; set; }
public int Clicks { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}

[Fact]
public void Where()
{
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM \"TB_TOPIC_DEL\" WHERE (\"ID\" = 1)", sql);

sql = delete.Where("id = @id", new { id = 1 }).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM \"TB_TOPIC_DEL\" 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_TOPIC_DEL\" 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_TOPIC_DEL\" WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
}
[Fact]
public void ExecuteAffrows()
{

var id = g.shentong.Insert<Topic>(new Topic { Title = "xxxx" }).ExecuteIdentity();
Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows());
}
[Fact]
public void ExecuteDeleted()
{

delete.Where(a => a.Id > 0).ExecuteDeleted();
}

[Fact]
public void AsTable()
{
Assert.Null(g.shentong.Delete<Topic>().ToSql());
var sql = g.shentong.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);

sql = g.shentong.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql);

sql = g.shentong.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.shentong.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql);
}
}
}
Loading

0 comments on commit 49aa899

Please sign in to comment.