Browse Source

Update oracle split bug

pull/14/head
sunkaixuan 3 years ago
parent
commit
16db118b77
  1. 100
      Src/Asp.Net/OracleTest/Demo/DemoN_SplitTable.cs
  2. 1
      Src/Asp.Net/OracleTest/OracleTest.csproj
  3. 3
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

100
Src/Asp.Net/OracleTest/Demo/DemoN_SplitTable.cs

@ -0,0 +1,100 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class DemoN_SplitTable
{
public static void Init()
{
Console.WriteLine("");
Console.WriteLine("#### CodeFirst Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true
});
db.Aop.OnLogExecuted = (s, p) =>
{
Console.WriteLine(s);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
};
//初始化分表
db.CodeFirst.SplitTables().InitTables<OrderSpliteTest>();
Console.WriteLine();
////根据最近3个表进行查询
var list = db.Queryable<OrderSpliteTest>()
.SplitTable(DateTime.Now.Date.AddYears(-1), DateTime.Now)
.ToList();
Console.WriteLine();
//根据时间选出的表进行查询
var list2 = db.Queryable<OrderSpliteTest>().SplitTable(tabs => tabs.Where(it=> it.Date>=DateTime.Now.AddYears(-2))).ToList();
Console.WriteLine();
//删除数据只在最近3张表执行操作
var x = db.Deleteable<OrderSpliteTest>().Where(it=>it.Pk==Guid.NewGuid()).SplitTable(tabs => tabs.Take(3)).ExecuteCommand();
Console.WriteLine();
var tableName = db.SplitHelper<OrderSpliteTest>().GetTableName(DateTime.Now.AddDays(0));
var listNull= db.Queryable<OrderSpliteTest>().SplitTable(ta => ta.InTableNames(tableName)).ToList();
var tableName2 = db.SplitHelper(new OrderSpliteTest() { Time=DateTime.Now}).GetTableNames();
var tableName3 = db.SplitHelper(new List<OrderSpliteTest> {
new OrderSpliteTest() { Time = DateTime.Now },
new OrderSpliteTest() { Time = DateTime.Now },
new OrderSpliteTest() { Time = DateTime.Now.AddMonths(-10) }
}).GetTableNames();
var x2 = db.Updateable<OrderSpliteTest>()
.SetColumns(it=>it.Name=="a")
.Where(it => it.Pk == Guid.NewGuid())
.SplitTable(tabs => tabs.InTableNames(tableName2))
.ExecuteCommand();
Console.WriteLine();
//按日分表
var x3 = db.Insertable(new OrderSpliteTest() { Name="A" }).SplitTable().ExecuteCommand();
Console.WriteLine();
////强制分表类型
var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" ,Time=DateTime.Now.AddDays(-1) }).SplitTable().ExecuteCommand();
//分表支持BulkCopy
//db.Fastest<OrderSpliteTest>().SplitTable().BulkCopy(new List<OrderSpliteTest> {
// new OrderSpliteTest() { Pk=Guid.NewGuid(),Name ="a", Time = DateTime.Now },
// new OrderSpliteTest() {Pk=Guid.NewGuid(),Name ="a", Time = DateTime.Now },
// new OrderSpliteTest() {Pk=Guid.NewGuid(),Name ="a", Time = DateTime.Now.AddMonths(-10) }
//});
//db.Fastest<OrderSpliteTest>().SplitTable().BulkUpdate(db.Queryable<OrderSpliteTest>().SplitTable(it=>it).ToList());
//db.Fastest<OrderSpliteTest>().SplitTable().BulkUpdate(db.Queryable<OrderSpliteTest>().SplitTable(it => it).ToList(),new string[] { "pk"},new string[] { "name"});
Console.WriteLine("#### CodeFirst end ####");
}
[SplitTable(SplitType.Day)]
[SqlSugar.SugarTable("Taxxx0101_{year}{month}{day}")]
public class OrderSpliteTest
{
[SugarColumn(IsPrimaryKey =true)]
public Guid Pk{ get; set; }
public string Name { get; set; }
[SugarColumn(IsNullable =true)]
[SplitField]
public DateTime Time { get; set; }
}
}
}

1
Src/Asp.Net/OracleTest/OracleTest.csproj

@ -65,6 +65,7 @@
<Compile Include="Demo\DemoF_Utilities.cs" /> <Compile Include="Demo\DemoF_Utilities.cs" />
<Compile Include="Demo\DemoG_SimpleClient.cs" /> <Compile Include="Demo\DemoG_SimpleClient.cs" />
<Compile Include="Demo\DemoJ_Report.cs" /> <Compile Include="Demo\DemoJ_Report.cs" />
<Compile Include="Demo\DemoN_SplitTable.cs" />
<Compile Include="Models\AttributeTable.cs" /> <Compile Include="Models\AttributeTable.cs" />
<Compile Include="Models\CarType.cs" /> <Compile Include="Models\CarType.cs" />
<Compile Include="Models\Custom.cs" /> <Compile Include="Models\Custom.cs" />

3
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -897,7 +897,8 @@ namespace SqlSugar
{ {
var splitColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.GetCustomAttribute<SplitFieldAttribute>() != null); var splitColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.GetCustomAttribute<SplitFieldAttribute>() != null);
var columnName = this.SqlBuilder.GetTranslationColumnName(splitColumn.DbColumnName); var columnName = this.SqlBuilder.GetTranslationColumnName(splitColumn.DbColumnName);
return this.Where($" {columnName}>=@spBeginTime AND {columnName}<= @spEndTime",new { spBeginTime = beginTime , spEndTime = endTime}).SplitTable(tas => { var sqlParameterKeyWord = this.SqlBuilder.SqlParameterKeyWord;
return this.Where($" {columnName}>={sqlParameterKeyWord}spBeginTime AND {columnName}<= {sqlParameterKeyWord}spEndTime",new { spBeginTime = beginTime , spEndTime = endTime}).SplitTable(tas => {
var dateNull = DateTime.MinValue; var dateNull = DateTime.MinValue;
var min = tas.Where(it => it.Date <= beginTime.Date).Select(it=>it.Date).OrderByDescending(it=>it.Date).FirstOrDefault(); var min = tas.Where(it => it.Date <= beginTime.Date).Select(it=>it.Date).OrderByDescending(it=>it.Date).FirstOrDefault();

Loading…
Cancel
Save