- 增加 AsTable 多次,可查询分表后的多个子表记录,以 UNION ALL 形式执行;

This commit is contained in:
28810
2019-09-09 18:30:55 +08:00
parent ebec260d97
commit bcc154ee43
13 changed files with 620 additions and 464 deletions

View File

@ -0,0 +1,34 @@
using FreeSql.DataAnnotations;
using FreeSql;
using System;
using System.Collections.Generic;
using Xunit;
using System.Linq;
using Newtonsoft.Json.Linq;
using NpgsqlTypes;
using Npgsql.LegacyPostgis;
using FreeSql.Internal;
using System.Linq.Expressions;
using FreeSql.Internal.Model;
namespace FreeSql.ExpressionTree
{
public class GetAllTableRuleTest
{
[Fact]
public void Test()
{
//var _tables = new List<SelectTableInfo>
//{
// [0] = new SelectTableInfo { }
//};
//var tableRuleInvoke = new Func<Type, string, string[]>((type, oldname) =>
//{
// return new[] { oldname };
//});
//CommonUtils.GetAllTableRule(_tables, tableRuleInvoke);
}
}
}

View File

@ -13,7 +13,7 @@ namespace FreeSql.Tests.MySqlMapType
[Column(MapType = typeof(DateTime))]
public DateTimeOffset dtos_to_dt { get; set; }
[Column(MapType = typeof(DateTime))]
[Column(MapType = typeof(DateTime?))]
public DateTimeOffset? dtosnullable_to_dt { get; set; }
}
[Fact]
@ -27,7 +27,7 @@ namespace FreeSql.Tests.MySqlMapType
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"));
Assert.Equal(item.dtosnullable_to_dt, find.dtosnullable_to_dt);
//update all
item.dtos_to_dt = DateTimeOffset.Now;
@ -36,7 +36,7 @@ namespace FreeSql.Tests.MySqlMapType
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"));
Assert.Equal(item.dtosnullable_to_dt, find.dtosnullable_to_dt);
item.dtosnullable_to_dt = DateTimeOffset.Now;
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().SetSource(item).ExecuteAffrows());

View File

@ -790,10 +790,22 @@ namespace FreeSql.Tests.Sqlite
else if (type == typeof(TestTypeInfo)) return oldname + "AsTable2";
return oldname + "AsTable";
};
Func<Type, string, string> tableRule2 = (type, oldname) =>
{
if (type == typeof(Topic)) return oldname + "Test2";
else if (type == typeof(TestTypeInfo)) return oldname + "Test2";
return oldname + "Test2";
};
var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).AsTable(tableRule).AsTable(tableRule2);
var sql = query.ToSql();
query = select.AsTable((type, oldname) => "table_1").AsTable((type, oldname) => "table_2").AsTable((type, oldname) => "table_3");
sql = query.ToSql(a => a.Id);
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).AsTable(tableRule);
var sql = query.ToSql().Replace("\r\n", "");
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).AsTable(tableRule);
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\"", sql);
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").AsTable(tableRule);

View File

@ -297,6 +297,7 @@ namespace FreeSql.Tests
public bool OptionsEntity02 { get; set; } = false;
public bool OptionsEntity03 { get; set; } = false;
public int OptionsEntity04 { get; set; }
public int? score { get; set; }
[Navigate("TbId")]
public virtual ICollection<TaskBuildInfo> Builds { get; set; }
@ -405,6 +406,8 @@ namespace FreeSql.Tests
[Fact]
public void Test1()
{
var testorderbysql = g.mysql.Select<TaskBuild>().OrderByDescending(a => a.OptionsEntity04 + (a.score ?? 0)).ToSql();
var testincludeMemberssql1 = g.sqlite.Select<TaskBuild>().Where(a => a.Templates.Title == "1").ToList();
var testincludeMemberssql2 = g.sqlite.Select<TaskBuild>().Include(a => a.Templates).ToList();