## v0.4.16

- 增加 ISelect.AsType 实现弱类型查询,配合 Select<object>().AsType(实体类型);
- 补充 ISelect.From<T2>;
- 补充 ExpressionTree 单元测试;
- 优化 ToList(a => new Dto()),会按优先级查询 Join 实体属性;
This commit is contained in:
28810
2019-04-16 22:48:11 +08:00
parent 66ec123d8a
commit 0d2191ca85
22 changed files with 1043 additions and 117 deletions

View File

@ -121,7 +121,8 @@ namespace FreeSql.Tests.PostgreSQL {
}
class TestDto {
public int id { get; set; }
public string name { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
[Fact]
public void ToList() {
@ -131,6 +132,11 @@ namespace FreeSql.Tests.PostgreSQL {
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
var testDto4 = select.Limit(10).ToList(a => new TestDto() { });
var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto());
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
var t1 = g.pgsql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
var t2 = g.pgsql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
@ -269,14 +275,21 @@ namespace FreeSql.Tests.PostgreSQL {
}
[Fact]
public void From() {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
var query2 = select.From<TestTypeInfo>((s, b) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
);
var sql2 = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\"", sql2);
query2.ToList();
var query3 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => b.ParentId == c.Id)
);
var sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql);
query2.ToList();
var sql3 = query3.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql3);
query3.ToList();
}
[Fact]
public void LeftJoin() {