mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
完成v0.3.17所有数据库的测试
This commit is contained in:
@ -680,15 +680,25 @@ namespace FreeSql.Tests.MySql {
|
||||
|
||||
[Fact]
|
||||
public void OrderBy() {
|
||||
var sql = select.OrderBy(a => new Random().NextDouble()).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Skip_Offset() {
|
||||
var sql = select.Offset(10).Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Take_Limit() {
|
||||
var sql = select.Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Page() {
|
||||
var sql1 = select.Page(1, 10).ToList();
|
||||
var sql2 = select.Page(2, 10).ToList();
|
||||
var sql3 = select.Page(3, 10).ToList();
|
||||
|
||||
var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList();
|
||||
var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList();
|
||||
var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Sum() {
|
||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Tests.Oracle {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
@ -40,6 +41,77 @@ namespace FreeSql.Tests.Oracle {
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
public partial class Song {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public DateTime? Create_time { get; set; }
|
||||
public bool? Is_deleted { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
public partial class Song_tag {
|
||||
public int Song_id { get; set; }
|
||||
public virtual Song Song { get; set; }
|
||||
|
||||
public int Tag_id { get; set; }
|
||||
public virtual Tag Tag { get; set; }
|
||||
}
|
||||
public partial class Tag {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public int? Parent_id { get; set; }
|
||||
public virtual Tag Parent { get; set; }
|
||||
|
||||
public decimal? Ddd { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Song> Songs { get; set; }
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsSelect() {
|
||||
//OneToOne、ManyToOne
|
||||
var t0 = g.oracle.Select<Tag>().Where(a => a.Parent.Parent.Name == "粤语").ToSql();
|
||||
//SELECT a.`Id`, a.`Parent_id`, a__Parent.`Id` as3, a__Parent.`Parent_id` as4, a__Parent.`Ddd`, a__Parent.`Name`, a.`Ddd` as7, a.`Name` as8
|
||||
//FROM `Tag` a
|
||||
//LEFT JOIN `Tag` a__Parent ON a__Parent.`Id` = a.`Parent_id`
|
||||
//LEFT JOIN `Tag` a__Parent__Parent ON a__Parent__Parent.`Id` = a__Parent.`Parent_id`
|
||||
//WHERE (a__Parent__Parent.`Name` = '粤语')
|
||||
|
||||
//OneToMany
|
||||
var t1 = g.oracle.Select<Tag>().Where(a => a.Tags.AsSelect().Any(t => t.Parent.Id == 10)).ToSql();
|
||||
//SELECT a.`Id`, a.`Parent_id`, a.`Ddd`, a.`Name`
|
||||
//FROM `Tag` a
|
||||
//WHERE (exists(SELECT 1
|
||||
// FROM `Tag` t
|
||||
// LEFT JOIN `Tag` t__Parent ON t__Parent.`Id` = t.`Parent_id`
|
||||
// WHERE (t__Parent.`Id` = 10) AND (t.`Parent_id` = a.`Id`)
|
||||
// limit 0,1))
|
||||
|
||||
//ManyToMany
|
||||
var t2 = g.oracle.Select<Song>().Where(s => s.Tags.AsSelect().Any(t => t.Name == "国语")).ToSql();
|
||||
//SELECT a.`Id`, a.`Create_time`, a.`Is_deleted`, a.`Title`, a.`Url`
|
||||
//FROM `Song` a
|
||||
//WHERE(exists(SELECT 1
|
||||
// FROM `Song_tag` Mt_Ms
|
||||
// WHERE(Mt_Ms.`Song_id` = a.`Id`) AND(exists(SELECT 1
|
||||
// FROM `Tag` t
|
||||
// WHERE(t.`Name` = '国语') AND(t.`Id` = Mt_Ms.`Tag_id`)
|
||||
// limit 0, 1))
|
||||
// limit 0, 1))
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lazy() {
|
||||
var tags = g.oracle.Select<Tag>().Where(a => a.Parent.Name == "xxx")
|
||||
.LeftJoin(a => a.Parent_id == a.Parent.Id)
|
||||
.ToSql();
|
||||
|
||||
var songs = g.oracle.Select<Song>().Limit(10).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDataTable() {
|
||||
@ -116,7 +188,7 @@ namespace FreeSql.Tests.Oracle {
|
||||
.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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TypeGuid\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
query2.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -124,33 +196,33 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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);
|
||||
var 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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_TOPIC22\" a LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON 1 = 1 LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx' WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
sql = query.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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
sql = query.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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_TOPIC22\" a LEFT JOIN \"TESTTYPEPARENTINFO\" b__Parent ON 1 = 1 LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx' WHERE (b__Parent.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -158,14 +230,14 @@ namespace FreeSql.Tests.Oracle {
|
||||
.LeftJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = b.\"PARENTID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -173,18 +245,18 @@ namespace FreeSql.Tests.Oracle {
|
||||
.LeftJoin(a => a.TypeGuid == b.Guid)
|
||||
.LeftJoin(a => b.ParentId == c.Id));
|
||||
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_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TypeGuid\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"");
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -192,33 +264,33 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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.InnerJoin(a => a.Type.Guid == a.TypeGuid);
|
||||
var 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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_TOPIC22\" a LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON 1 = 1 INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx' WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
sql = query.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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
sql = query.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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_TOPIC22\" a LEFT JOIN \"TESTTYPEPARENTINFO\" b__Parent ON 1 = 1 INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx' WHERE (b__Parent.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -226,14 +298,14 @@ namespace FreeSql.Tests.Oracle {
|
||||
.InnerJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.InnerJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" INNER JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" INNER JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = b.\"PARENTID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -241,18 +313,18 @@ namespace FreeSql.Tests.Oracle {
|
||||
.InnerJoin(a => a.TypeGuid == b.Guid)
|
||||
.InnerJoin(a => b.ParentId == c.Id));
|
||||
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_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON a.\"TypeGuid\" = b.\"GUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"");
|
||||
query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
@ -261,33 +333,33 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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.RightJoin(a => a.Type.Guid == a.TypeGuid);
|
||||
var 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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_TOPIC22\" a LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON 1 = 1 RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx' WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
sql = query.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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
sql = query.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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.RightJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_TOPIC22\" a LEFT JOIN \"TESTTYPEPARENTINFO\" b__Parent ON 1 = 1 RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx' WHERE (b__Parent.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -295,14 +367,14 @@ namespace FreeSql.Tests.Oracle {
|
||||
.RightJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" RIGHT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.RightJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TypeGuid\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = b.\"PARENTID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -310,18 +382,18 @@ namespace FreeSql.Tests.Oracle {
|
||||
.RightJoin(a => a.TypeGuid == b.Guid)
|
||||
.RightJoin(a => b.ParentId == c.Id));
|
||||
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_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON a.\"TypeGuid\" = b.\"GUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"");
|
||||
query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
@ -330,48 +402,48 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" a__Type WHERE (a__Type.\"NAME\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" a__Type WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TYPEGUID\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" a__Type, \"TESTTYPEPARENTINFO\" a__Type__Parent WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><F2B5A5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.Where<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where<TestTypeInfo>((a, b) => b.Name == "typeTitle" && b.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"NAME\" = 'typeTitle' AND b.\"GUID\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"NAME\" = 'typeTitle' AND b.\"GUID\" = a.\"TYPEGUID\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where<TestTypeInfo, TestTypeParentInfo>((a, b, c) => c.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEPARENTINFO\" c WHERE (c.\"NAME\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEPARENTINFO\" c WHERE (c.\"NAME\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -379,13 +451,13 @@ namespace FreeSql.Tests.Oracle {
|
||||
.Where(a => a.Id == 10 && c.Name == "xxx")
|
||||
.Where(a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEPARENTINFO\" c, \"TESTTYPEINFO\" b WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -393,32 +465,32 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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.WhereIf(true, a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" a__Type WHERE (a__Type.\"NAME\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" a__Type WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TYPEGUID\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" a__Type, \"TESTTYPEPARENTINFO\" a__Type__Parent WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -426,13 +498,13 @@ namespace FreeSql.Tests.Oracle {
|
||||
.WhereIf(true, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(true, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEPARENTINFO\" c, \"TESTTYPEINFO\" b WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
@ -440,32 +512,32 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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>
|
||||
query = select.WhereIf(false, a => a.Id == 10);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Id == 10).WhereIf(false, a => a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -473,13 +545,13 @@ namespace FreeSql.Tests.Oracle {
|
||||
.WhereIf(false, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(false, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -519,15 +591,25 @@ namespace FreeSql.Tests.Oracle {
|
||||
}
|
||||
[Fact]
|
||||
public void OrderBy() {
|
||||
var sql = select.Offset(10).OrderBy(a => new Random().NextDouble()).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Skip_Offset() {
|
||||
var sql = select.Offset(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Take_Limit() {
|
||||
var sql = select.Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Page() {
|
||||
var sql1 = select.Page(1, 10).ToList();
|
||||
var sql2 = select.Page(2, 10).ToList();
|
||||
var sql3 = select.Page(3, 10).ToList();
|
||||
|
||||
var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList();
|
||||
var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList();
|
||||
var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Sum() {
|
||||
@ -556,57 +638,57 @@ namespace FreeSql.Tests.Oracle {
|
||||
//<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", "");
|
||||
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);
|
||||
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);
|
||||
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\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
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\" AND a__Type.\"NAME\" = 'xxx'", sql);
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).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 \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON 1 = 1 LEFT JOIN \"TESTTYPEINFOAsTable2\" a__Type ON a__Type.\"GUID\" = a.\"TypeGuid\" AND a__Type.\"NAME\" = 'xxx' WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
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\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid).AsTable(tableRule);
|
||||
sql = query.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_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").AsTable(tableRule);
|
||||
sql = query.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_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql);
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
query = select.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
sql = query.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_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" b__Parent ON 1 = 1 LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TypeGuid\" AND b.\"NAME\" = 'xxx' WHERE (b__Parent.\"ID\" = 10)", sql);
|
||||
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\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select
|
||||
.LeftJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).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\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
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\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
|
||||
sql = query.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_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TypeGuid\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" c ON c.\"ID\" = b.\"PARENTID\"", sql);
|
||||
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\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
.LeftJoin(a => a.TypeGuid == b.Guid)
|
||||
.LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
|
||||
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_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON a.\"TypeGuid\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"").AsTable(tableRule);
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"").AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TypeGuid\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TypeGuid\" and b.\"NAME\" = :bname", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace FreeSql.Tests.OracleExpression {
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Tests.OracleExpression {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
@ -31,6 +32,77 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
public partial class Song {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public DateTime? Create_time { get; set; }
|
||||
public bool? Is_deleted { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
public partial class Song_tag {
|
||||
public int Song_id { get; set; }
|
||||
public virtual Song Song { get; set; }
|
||||
|
||||
public int Tag_id { get; set; }
|
||||
public virtual Tag Tag { get; set; }
|
||||
}
|
||||
public partial class Tag {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public int? Parent_id { get; set; }
|
||||
public virtual Tag Parent { get; set; }
|
||||
|
||||
public decimal? Ddd { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Song> Songs { get; set; }
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsSelect() {
|
||||
//OneToOne、ManyToOne
|
||||
var t0 = g.pgsql.Select<Tag>().Where(a => a.Parent.Parent.Name == "粤语").ToSql();
|
||||
//SELECT a.`Id`, a.`Parent_id`, a__Parent.`Id` as3, a__Parent.`Parent_id` as4, a__Parent.`Ddd`, a__Parent.`Name`, a.`Ddd` as7, a.`Name` as8
|
||||
//FROM `Tag` a
|
||||
//LEFT JOIN `Tag` a__Parent ON a__Parent.`Id` = a.`Parent_id`
|
||||
//LEFT JOIN `Tag` a__Parent__Parent ON a__Parent__Parent.`Id` = a__Parent.`Parent_id`
|
||||
//WHERE (a__Parent__Parent.`Name` = '粤语')
|
||||
|
||||
//OneToMany
|
||||
var t1 = g.pgsql.Select<Tag>().Where(a => a.Tags.AsSelect().Any(t => t.Parent.Id == 10)).ToSql();
|
||||
//SELECT a.`Id`, a.`Parent_id`, a.`Ddd`, a.`Name`
|
||||
//FROM `Tag` a
|
||||
//WHERE (exists(SELECT 1
|
||||
// FROM `Tag` t
|
||||
// LEFT JOIN `Tag` t__Parent ON t__Parent.`Id` = t.`Parent_id`
|
||||
// WHERE (t__Parent.`Id` = 10) AND (t.`Parent_id` = a.`Id`)
|
||||
// limit 0,1))
|
||||
|
||||
//ManyToMany
|
||||
var t2 = g.pgsql.Select<Song>().Where(s => s.Tags.AsSelect().Any(t => t.Name == "国语")).ToSql();
|
||||
//SELECT a.`Id`, a.`Create_time`, a.`Is_deleted`, a.`Title`, a.`Url`
|
||||
//FROM `Song` a
|
||||
//WHERE(exists(SELECT 1
|
||||
// FROM `Song_tag` Mt_Ms
|
||||
// WHERE(Mt_Ms.`Song_id` = a.`Id`) AND(exists(SELECT 1
|
||||
// FROM `Tag` t
|
||||
// WHERE(t.`Name` = '国语') AND(t.`Id` = Mt_Ms.`Tag_id`)
|
||||
// limit 0, 1))
|
||||
// limit 0, 1))
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lazy() {
|
||||
var tags = g.pgsql.Select<Tag>().Where(a => a.Parent.Name == "xxx")
|
||||
.LeftJoin(a => a.Parent_id == a.Parent.Id)
|
||||
.ToSql();
|
||||
|
||||
var songs = g.pgsql.Select<Song>().Limit(10).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDataTable() {
|
||||
@ -184,7 +256,7 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.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);
|
||||
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();
|
||||
}
|
||||
[Fact]
|
||||
@ -192,33 +264,33 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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);
|
||||
var 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_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
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_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic\" a LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON 1 = 1 LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx' WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
sql = query.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 b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
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 b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
sql = query.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 b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx'", sql);
|
||||
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 b.\"guid\" = a.\"typeguid\" AND b.\"name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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 \"testtypeparentinfo\" b__Parent ON 1 = 1 LEFT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx' WHERE (b__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -226,14 +298,14 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.LeftJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
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_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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 b.\"guid\" = a.\"TypeGuid\" LEFT JOIN \"testtypeparentinfo\" c ON c.\"id\" = b.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" LEFT JOIN \"testtypeparentinfo\" c ON c.\"id\" = a__Type.\"parentid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -241,18 +313,18 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.LeftJoin(a => a.TypeGuid == b.Guid)
|
||||
.LeftJoin(a => b.ParentId == c.Id));
|
||||
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);
|
||||
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();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"");
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", new { bname = "xxx" });
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -260,33 +332,33 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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.InnerJoin(a => a.Type.Guid == a.TypeGuid);
|
||||
var 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_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
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_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic\" a LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON 1 = 1 INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx' WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
sql = query.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 INNER JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
sql = query.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 INNER JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"typeguid\" AND b.\"name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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 \"testtypeparentinfo\" b__Parent ON 1 = 1 INNER JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx' WHERE (b__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -294,14 +366,14 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.InnerJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.InnerJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
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_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" INNER JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" INNER JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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 INNER JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" INNER JOIN \"testtypeparentinfo\" c ON c.\"id\" = b.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" INNER JOIN \"testtypeparentinfo\" c ON c.\"id\" = a__Type.\"parentid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -309,18 +381,18 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.InnerJoin(a => a.TypeGuid == b.Guid)
|
||||
.InnerJoin(a => b.ParentId == c.Id));
|
||||
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 INNER JOIN \"testtypeinfo\" b ON a.\"TypeGuid\" = b.\"guid\" INNER JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\" INNER JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.InnerJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"");
|
||||
query = select.InnerJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", new { bname = "xxx" });
|
||||
query = select.InnerJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
@ -329,33 +401,33 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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.RightJoin(a => a.Type.Guid == a.TypeGuid);
|
||||
var 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_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
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_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic\" a LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON 1 = 1 RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx' WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
sql = query.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 RIGHT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
sql = query.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 RIGHT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"typeguid\" AND b.\"name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.RightJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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 \"testtypeparentinfo\" b__Parent ON 1 = 1 RIGHT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx' WHERE (b__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -363,14 +435,14 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.RightJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
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_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" RIGHT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" RIGHT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.RightJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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 RIGHT JOIN \"testtypeinfo\" b ON b.\"guid\" = a.\"TypeGuid\" RIGHT JOIN \"testtypeparentinfo\" c ON c.\"id\" = b.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" RIGHT JOIN \"testtypeparentinfo\" c ON c.\"id\" = a__Type.\"parentid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -378,18 +450,18 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.RightJoin(a => a.TypeGuid == b.Guid)
|
||||
.RightJoin(a => b.ParentId == c.Id));
|
||||
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 RIGHT JOIN \"testtypeinfo\" b ON a.\"TypeGuid\" = b.\"guid\" RIGHT JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\" RIGHT JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.RightJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"");
|
||||
query = select.RightJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", new { bname = "xxx" });
|
||||
query = select.RightJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
@ -398,48 +470,48 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10) AND (a.\"clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10) AND (a.\"clicks\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" a__Type WHERE (a__Type.\"name\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" WHERE (a__Type.\"name\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" a__Type WHERE (a__Type.\"name\" = 'typeTitle' AND a__Type.\"guid\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" WHERE (a__Type.\"name\" = 'typeTitle' AND a__Type.\"guid\" = a.\"typeguid\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" a__Type, \"testtypeparentinfo\" a__Type__Parent WHERE (a__Type__Parent.\"name\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"name\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><F2B5A5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.Where<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b WHERE (b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b WHERE (b.\"guid\" = a.\"typeguid\" AND b.\"name\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where<TestTypeInfo>((a, b) => b.Name == "typeTitle" && b.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b WHERE (b.\"name\" = 'typeTitle' AND b.\"guid\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b WHERE (b.\"name\" = 'typeTitle' AND b.\"guid\" = a.\"typeguid\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where<TestTypeInfo, TestTypeParentInfo>((a, b, c) => c.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeparentinfo\" c WHERE (c.\"name\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeparentinfo\" c WHERE (c.\"name\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -447,13 +519,13 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.Where(a => a.Id == 10 && c.Name == "xxx")
|
||||
.Where(a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeparentinfo\" c, \"testtypeinfo\" b WHERE (a.\"id\" = 10 AND c.\"name\" = 'xxx') AND (b.\"parentid\" = 20)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b, \"testtypeparentinfo\" c WHERE (a.\"id\" = 10 AND c.\"name\" = 'xxx') AND (b.\"parentid\" = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.\"clicks\" > 100 and a.\"id\" = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = @id)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = @id)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -461,32 +533,32 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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.WhereIf(true, a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10) AND (a.\"clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10) AND (a.\"clicks\" > 100)", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" a__Type WHERE (a__Type.\"name\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" WHERE (a__Type.\"name\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" a__Type WHERE (a__Type.\"name\" = 'typeTitle' AND a__Type.\"guid\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" WHERE (a__Type.\"name\" = 'typeTitle' AND a__Type.\"guid\" = a.\"typeguid\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" a__Type, \"testtypeparentinfo\" a__Type__Parent WHERE (a__Type__Parent.\"name\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" LEFT JOIN \"testtypeparentinfo\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"name\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -494,13 +566,13 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.WhereIf(true, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(true, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeparentinfo\" c, \"testtypeinfo\" b WHERE (a.\"id\" = 10 AND c.\"name\" = 'xxx') AND (b.\"parentid\" = 20)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b, \"testtypeparentinfo\" c WHERE (a.\"id\" = 10 AND c.\"name\" = 'xxx') AND (b.\"parentid\" = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.\"clicks\" > 100 and a.\"id\" = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = @id)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = @id)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
@ -508,32 +580,32 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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>
|
||||
query = select.WhereIf(false, a => a.Id == 10);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Id == 10).WhereIf(false, a => a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(false, a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -541,13 +613,13 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
.WhereIf(false, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(false, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a, \"testtypeinfo\" b, \"testtypeparentinfo\" c", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.\"clicks\" > 100 and a.\"id\" = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -587,15 +659,25 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
}
|
||||
[Fact]
|
||||
public void OrderBy() {
|
||||
var sql = select.OrderBy(a => new Random().NextDouble()).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Skip_Offset() {
|
||||
var sql = select.Offset(10).Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Take_Limit() {
|
||||
var sql = select.Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Page() {
|
||||
var sql1 = select.Page(1, 10).ToList();
|
||||
var sql2 = select.Page(2, 10).ToList();
|
||||
var sql3 = select.Page(3, 10).ToList();
|
||||
|
||||
var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList();
|
||||
var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList();
|
||||
var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Sum() {
|
||||
@ -624,57 +706,57 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
//<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", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" 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);
|
||||
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_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx'", sql);
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).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_topicAsTable1\" a LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON 1 = 1 LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" AND a__Type.\"name\" = 'xxx' WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid).AsTable(tableRule);
|
||||
sql = query.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_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"typeguid\"", sql);
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").AsTable(tableRule);
|
||||
sql = query.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_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx'", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"typeguid\" AND b.\"name\" = 'xxx'", sql);
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
query = select.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
sql = query.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_topicAsTable1\" a LEFT JOIN \"testtypeparentinfoAsTable\" b__Parent ON 1 = 1 LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"TypeGuid\" AND b.\"name\" = 'xxx' WHERE (b__Parent.\"id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" AND a__Type.\"name\" = 'xxx' LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\" WHERE (a__Type__Parent.\"id\" = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select
|
||||
.LeftJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).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_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"TypeGuid\" LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
|
||||
sql = query.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_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"TypeGuid\" LEFT JOIN \"testtypeparentinfoAsTable\" c ON c.\"id\" = b.\"parentid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"typeguid\" LEFT JOIN \"testtypeparentinfoAsTable\" c ON c.\"id\" = a__Type.\"parentid\"", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
.LeftJoin(a => a.TypeGuid == b.Guid)
|
||||
.LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
|
||||
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_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON a.\"TypeGuid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfoAsTable\" c ON b.\"parentid\" = c.\"id\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON a.\"typeguid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfoAsTable\" c ON b.\"parentid\" = c.\"id\"", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"").AsTable(tableRule);
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"").AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\"", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"TypeGuid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"TypeGuid\" and b.\"name\" = @bname", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ namespace FreeSql.Tests.PostgreSQLExpression {
|
||||
[Fact]
|
||||
public void ToChar() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList());
|
||||
data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList());
|
||||
//data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList());
|
||||
//data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDateTime() {
|
||||
|
@ -21,6 +21,7 @@ namespace FreeSql.Tests.PostgreSQLExpression {
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Tests.PostgreSQLExpression {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -29,6 +29,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
@ -40,7 +41,79 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
public partial class Song {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public DateTime? Create_time { get; set; }
|
||||
public bool? Is_deleted { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
public partial class Song_tag {
|
||||
public int Song_id { get; set; }
|
||||
public virtual Song Song { get; set; }
|
||||
|
||||
public int Tag_id { get; set; }
|
||||
public virtual Tag Tag { get; set; }
|
||||
}
|
||||
public partial class Tag {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public int? Parent_id { get; set; }
|
||||
public virtual Tag Parent { get; set; }
|
||||
|
||||
public decimal? Ddd { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Song> Songs { get; set; }
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsSelect() {
|
||||
//OneToOne、ManyToOne
|
||||
var t0 = _sqlserverFixture.SqlServer.Select<Tag>().Where(a => a.Parent.Parent.Name == "粤语").ToSql();
|
||||
//SELECT a.[Id], a.[Parent_id], a__Parent.[Id] as3, a__Parent.[Parent_id] as4, a__Parent.[Ddd], a__Parent.[Name], a.[Ddd] as7, a.[Name] as8
|
||||
//FROM [Tag] a
|
||||
//LEFT JOIN [Tag] a__Parent ON a__Parent.[Id] = a.[Parent_id]
|
||||
//LEFT JOIN [Tag] a__Parent__Parent ON a__Parent__Parent.[Id] = a__Parent.[Parent_id]
|
||||
//WHERE (a__Parent__Parent.[Name] = '粤语')
|
||||
|
||||
//OneToMany
|
||||
var t1 = _sqlserverFixture.SqlServer.Select<Tag>().Where(a => a.Tags.AsSelect().Any(t => t.Parent.Id == 10)).ToSql();
|
||||
//SELECT a.[Id], a.[Parent_id], a.[Ddd], a.[Name]
|
||||
//FROM [Tag] a
|
||||
//WHERE (exists(SELECT 1
|
||||
// FROM [Tag] t
|
||||
// LEFT JOIN [Tag] t__Parent ON t__Parent.[Id] = t.[Parent_id]
|
||||
// WHERE (t__Parent.[Id] = 10) AND (t.[Parent_id] = a.[Id])
|
||||
// limit 0,1))
|
||||
|
||||
//ManyToMany
|
||||
var t2 = _sqlserverFixture.SqlServer.Select<Song>().Where(s => s.Tags.AsSelect().Any(t => t.Name == "国语")).ToSql();
|
||||
//SELECT a.[Id], a.[Create_time], a.[Is_deleted], a.[Title], a.[Url]
|
||||
//FROM [Song] a
|
||||
//WHERE(exists(SELECT 1
|
||||
// FROM [Song_tag] Mt_Ms
|
||||
// WHERE(Mt_Ms.[Song_id] = a.[Id]) AND(exists(SELECT 1
|
||||
// FROM [Tag] t
|
||||
// WHERE(t.[Name] = '国语') AND(t.[Id] = Mt_Ms.[Tag_id])
|
||||
// limit 0, 1))
|
||||
// limit 0, 1))
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lazy() {
|
||||
var tags = g.sqlite.Select<Tag>().Where(a => a.Parent.Name == "xxx")
|
||||
.LeftJoin(a => a.Parent_id == a.Parent.Id)
|
||||
.ToSql();
|
||||
|
||||
var songs = g.sqlite.Select<Song>().Limit(10).ToList();
|
||||
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ToDataTable() {
|
||||
var items = new List<Topic>();
|
||||
@ -135,7 +208,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic22] a LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON 1 = 1 LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -151,7 +224,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_topic22] a LEFT JOIN [TestTypeParentInfo] b__Parent ON 1 = 1 LEFT JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' WHERE (b__Parent.[Id] = 10)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -163,10 +236,10 @@ namespace FreeSql.Tests.SqlServer {
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_topic22] a LEFT JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] c ON c.[Id] = b.[ParentId]", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] c ON c.[Id] = a__Type.[ParentId]", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -203,7 +276,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic22] a LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON 1 = 1 INNER JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a INNER JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -219,7 +292,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_topic22] a LEFT JOIN [TestTypeParentInfo] b__Parent ON 1 = 1 INNER JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' WHERE (b__Parent.[Id] = 10)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a INNER JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -231,10 +304,10 @@ namespace FreeSql.Tests.SqlServer {
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_topic22] a INNER JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] INNER JOIN [TestTypeParentInfo] c ON c.[Id] = b.[ParentId]", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a INNER JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] INNER JOIN [TestTypeParentInfo] c ON c.[Id] = a__Type.[ParentId]", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -272,7 +345,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic22] a LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON 1 = 1 RIGHT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a RIGHT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -288,7 +361,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_topic22] a LEFT JOIN [TestTypeParentInfo] b__Parent ON 1 = 1 RIGHT JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' WHERE (b__Parent.[Id] = 10)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a RIGHT JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -300,10 +373,10 @@ namespace FreeSql.Tests.SqlServer {
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.RightJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_topic22] a RIGHT JOIN [TestTypeInfo] b ON b.[Guid] = a.[TypeGuid] RIGHT JOIN [TestTypeParentInfo] c ON c.[Id] = b.[ParentId]", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a RIGHT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] RIGHT JOIN [TestTypeParentInfo] c ON c.[Id] = a__Type.[ParentId]", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -346,19 +419,19 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] a__Type WHERE (a__Type.[Name] = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] WHERE (a__Type.[Name] = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] a__Type WHERE (a__Type.[Name] = 'typeTitle' AND a__Type.[Guid] = a.[TypeGuid])", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] WHERE (a__Type.[Name] = 'typeTitle' AND a__Type.[Guid] = a.[TypeGuid])", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] a__Type, [TestTypeParentInfo] a__Type__Parent WHERE (a__Type__Parent.[Name] = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Name] = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><F2B5A5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.Where<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
@ -380,7 +453,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
.Where(a => a.Id == 10 && c.Name == "xxx")
|
||||
.Where(a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeParentInfo] c, [TestTypeInfo] b WHERE (a.[Id] = 10 AND c.[Name] = 'xxx') AND (b.[ParentId] = 20)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] b, [TestTypeParentInfo] c WHERE (a.[Id] = 10 AND c.[Name] = 'xxx') AND (b.[ParentId] = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
@ -409,17 +482,17 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] a__Type WHERE (a__Type.[Name] = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] WHERE (a__Type.[Name] = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] a__Type WHERE (a__Type.[Name] = 'typeTitle' AND a__Type.[Guid] = a.[TypeGuid])", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] WHERE (a__Type.[Name] = 'typeTitle' AND a__Type.[Guid] = a.[TypeGuid])", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] a__Type, [TestTypeParentInfo] a__Type__Parent WHERE (a__Type__Parent.[Name] = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfo] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Name] = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -427,7 +500,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
.WhereIf(true, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(true, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeParentInfo] c, [TestTypeInfo] b WHERE (a.[Id] = 10 AND c.[Name] = 'xxx') AND (b.[ParentId] = 20)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] b, [TestTypeParentInfo] c WHERE (a.[Id] = 10 AND c.[Name] = 'xxx') AND (b.[ParentId] = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
@ -474,7 +547,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
.WhereIf(false, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(false, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] b, [TestTypeParentInfo] c", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
@ -520,15 +593,25 @@ namespace FreeSql.Tests.SqlServer {
|
||||
}
|
||||
[Fact]
|
||||
public void OrderBy() {
|
||||
var sql = select.OrderBy(a => new Random().NextDouble()).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Skip_Offset() {
|
||||
var sql = select.Offset(10).Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Take_Limit() {
|
||||
var sql = select.Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Page() {
|
||||
var sql1 = select.Page(1, 10).ToList();
|
||||
var sql2 = select.Page(2, 10).ToList();
|
||||
var sql3 = select.Page(3, 10).ToList();
|
||||
|
||||
var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList();
|
||||
var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList();
|
||||
var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Sum() {
|
||||
@ -565,7 +648,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).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 [TestTypeParentInfoAsTable] a__Type__Parent ON 1 = 1 LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TypeGuid] AND a__Type.[Name] = 'xxx' WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
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] AND a__Type.[Name] = 'xxx' LEFT JOIN [TestTypeParentInfoAsTable] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid).AsTable(tableRule);
|
||||
@ -578,7 +661,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
sql = query.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_topic22AsTable1] a LEFT JOIN [TestTypeParentInfoAsTable] b__Parent ON 1 = 1 LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' WHERE (b__Parent.[Id] = 10)", sql);
|
||||
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] b ON b.[Guid] = a.[TypeGuid] AND b.[Name] = 'xxx' LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfoAsTable] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId] WHERE (a__Type__Parent.[Id] = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select
|
||||
@ -591,7 +674,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
|
||||
sql = query.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_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfoAsTable] c ON c.[Id] = b.[ParentId]", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TypeGuid] LEFT JOIN [TestTypeParentInfoAsTable] c ON c.[Id] = a__Type.[ParentId]", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
@ -601,13 +684,13 @@ namespace FreeSql.Tests.SqlServer {
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] b ON a.[TypeGuid] = b.[Guid] LEFT JOIN [TestTypeParentInfoAsTable] c ON b.[ParentId] = c.[Id]", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.LeftJoin("[TestTypeInfo] b on b.[Guid] = a.[TypeGuid]").AsTable(tableRule);
|
||||
query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid").AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfo] b on b.[Guid] = a.[TypeGuid]", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
|
||||
query = select.LeftJoin("[TestTypeInfo] b on b.[Guid] = a.[TypeGuid] and b.[Name] = @bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = @bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfo] b on b.[Guid] = a.[TypeGuid] and b.[Name] = @bname", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = @bname", sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ namespace FreeSql.Tests.SqlServerExpression {
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -29,6 +29,7 @@ namespace FreeSql.Tests.SqlServerExpression {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
@ -62,6 +63,39 @@ namespace FreeSql.Tests.Sqlite {
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsSelect() {
|
||||
//OneToOne、ManyToOne
|
||||
var t0 = g.sqlite.Select<Tag>().Where(a => a.Parent.Parent.Name == "粤语").ToSql();
|
||||
//SELECT a.`Id`, a.`Parent_id`, a__Parent.`Id` as3, a__Parent.`Parent_id` as4, a__Parent.`Ddd`, a__Parent.`Name`, a.`Ddd` as7, a.`Name` as8
|
||||
//FROM `Tag` a
|
||||
//LEFT JOIN `Tag` a__Parent ON a__Parent.`Id` = a.`Parent_id`
|
||||
//LEFT JOIN `Tag` a__Parent__Parent ON a__Parent__Parent.`Id` = a__Parent.`Parent_id`
|
||||
//WHERE (a__Parent__Parent.`Name` = '粤语')
|
||||
|
||||
//OneToMany
|
||||
var t1 = g.sqlite.Select<Tag>().Where(a => a.Tags.AsSelect().Any(t => t.Parent.Id == 10)).ToSql();
|
||||
//SELECT a.`Id`, a.`Parent_id`, a.`Ddd`, a.`Name`
|
||||
//FROM `Tag` a
|
||||
//WHERE (exists(SELECT 1
|
||||
// FROM `Tag` t
|
||||
// LEFT JOIN `Tag` t__Parent ON t__Parent.`Id` = t.`Parent_id`
|
||||
// WHERE (t__Parent.`Id` = 10) AND (t.`Parent_id` = a.`Id`)
|
||||
// limit 0,1))
|
||||
|
||||
//ManyToMany
|
||||
var t2 = g.sqlite.Select<Song>().Where(s => s.Tags.AsSelect().Any(t => t.Name == "国语")).ToSql();
|
||||
//SELECT a.`Id`, a.`Create_time`, a.`Is_deleted`, a.`Title`, a.`Url`
|
||||
//FROM `Song` a
|
||||
//WHERE(exists(SELECT 1
|
||||
// FROM `Song_tag` Mt_Ms
|
||||
// WHERE(Mt_Ms.`Song_id` = a.`Id`) AND(exists(SELECT 1
|
||||
// FROM `Tag` t
|
||||
// WHERE(t.`Name` = '国语') AND(t.`Id` = Mt_Ms.`Tag_id`)
|
||||
// limit 0, 1))
|
||||
// limit 0, 1))
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lazy() {
|
||||
var tags = g.sqlite.Select<Tag>().Where(a => a.Parent.Name == "xxx")
|
||||
@ -166,7 +200,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic22\" a LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON 1 = 1 LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -180,9 +214,9 @@ namespace FreeSql.Tests.Sqlite {
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_topic22\" a LEFT JOIN \"TestTypeParentInfo\" b__Parent ON 1 = 1 LEFT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -194,10 +228,10 @@ namespace FreeSql.Tests.Sqlite {
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_topic22\" a LEFT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" LEFT JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = b.\"ParentId\"", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" LEFT JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = a__Type.\"ParentId\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -234,7 +268,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
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_topic22\" a LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON 1 = 1 INNER JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -248,9 +282,9 @@ namespace FreeSql.Tests.Sqlite {
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx'", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
query = select.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
sql = query.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_topic22\" a LEFT JOIN \"TestTypeParentInfo\" b__Parent ON 1 = 1 INNER JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -262,10 +296,10 @@ namespace FreeSql.Tests.Sqlite {
|
||||
query.ToList();
|
||||
|
||||
query = select
|
||||
.InnerJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.InnerJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
sql = query.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_topic22\" a INNER JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" INNER JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = b.\"ParentId\"", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" INNER JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = a__Type.\"ParentId\"", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
@ -290,72 +324,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
}
|
||||
[Fact]
|
||||
public void RightJoin() {
|
||||
////<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.RightJoin(a => a.Type.Guid == a.TypeGuid);
|
||||
//var 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_topic22\" a RIGHT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\"", sql);
|
||||
//query.ToList();
|
||||
|
||||
//query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||
//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_topic22\" a RIGHT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx'", sql);
|
||||
//query.ToList();
|
||||
|
||||
//query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
//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_topic22\" a LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON 1 = 1 RIGHT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
//query.ToList();
|
||||
|
||||
////<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid);
|
||||
//sql = query.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_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\"", sql);
|
||||
//query.ToList();
|
||||
|
||||
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx");
|
||||
//sql = query.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_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx'", sql);
|
||||
//query.ToList();
|
||||
|
||||
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
||||
//sql = query.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_topic22\" a LEFT JOIN \"TestTypeParentInfo\" b__Parent ON 1 = 1 RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
|
||||
//query.ToList();
|
||||
|
||||
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//query = select
|
||||
// .RightJoin(a => a.Type.Guid == a.TypeGuid)
|
||||
// .RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||
//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_topic22\" a RIGHT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" RIGHT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\"", sql);
|
||||
//query.ToList();
|
||||
|
||||
//query = select
|
||||
// .RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
// .RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||
//sql = query.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_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TypeGuid\" RIGHT JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = b.\"ParentId\"", sql);
|
||||
//query.ToList();
|
||||
|
||||
////<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
//var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
// .RightJoin(a => a.TypeGuid == b.Guid)
|
||||
// .RightJoin(a => b.ParentId == c.Id));
|
||||
//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_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON a.\"TypeGuid\" = b.\"Guid\" RIGHT JOIN \"TestTypeParentInfo\" c ON b.\"ParentId\" = c.\"Id\"", sql);
|
||||
//query2.ToList();
|
||||
|
||||
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
//query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TypeGuid\"");
|
||||
//sql = query.ToSql().Replace("\r\n", "");
|
||||
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TypeGuid\"", sql);
|
||||
//query.ToList();
|
||||
|
||||
//query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TypeGuid\" and b.\"Name\" = @bname", new { bname = "xxx" });
|
||||
//sql = query.ToSql().Replace("\r\n", "");
|
||||
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TypeGuid\" and b.\"Name\" = @bname", sql);
|
||||
//query.ToList();
|
||||
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void Where() {
|
||||
@ -377,17 +346,17 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" a__Type WHERE (a__Type.\"Name\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" WHERE (a__Type.\"Name\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" a__Type WHERE (a__Type.\"Name\" = 'typeTitle' AND a__Type.\"Guid\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" WHERE (a__Type.\"Name\" = 'typeTitle' AND a__Type.\"Guid\" = a.\"TypeGuid\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" a__Type, \"TestTypeParentInfo\" a__Type__Parent WHERE (a__Type__Parent.\"Name\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Name\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><F2B5A5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -411,7 +380,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
.Where(a => a.Id == 10 && c.Name == "xxx")
|
||||
.Where(a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeParentInfo\" c, \"TestTypeInfo\" b WHERE (a.\"Id\" = 10 AND c.\"Name\" = 'xxx') AND (b.\"ParentId\" = 20)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" b, \"TestTypeParentInfo\" c WHERE (a.\"Id\" = 10 AND c.\"Name\" = 'xxx') AND (b.\"ParentId\" = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
@ -440,17 +409,17 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" a__Type WHERE (a__Type.\"Name\" = 'typeTitle')", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" WHERE (a__Type.\"Name\" = 'typeTitle')", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" a__Type WHERE (a__Type.\"Name\" = 'typeTitle' AND a__Type.\"Guid\" = a.\"TypeGuid\")", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" WHERE (a__Type.\"Name\" = 'typeTitle' AND a__Type.\"Guid\" = a.\"TypeGuid\")", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Type.Parent.Name == "tparent");
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" a__Type, \"TestTypeParentInfo\" a__Type__Parent WHERE (a__Type__Parent.\"Name\" = 'tparent')", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Name\" = 'tparent')", sql);
|
||||
query.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> From <20><>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -458,7 +427,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
.WhereIf(true, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(true, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeParentInfo\" c, \"TestTypeInfo\" b WHERE (a.\"Id\" = 10 AND c.\"Name\" = 'xxx') AND (b.\"ParentId\" = 20)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" b, \"TestTypeParentInfo\" c WHERE (a.\"Id\" = 10 AND c.\"Name\" = 'xxx') AND (b.\"ParentId\" = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
@ -505,7 +474,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
.WhereIf(false, a => a.Id == 10 && c.Name == "xxx")
|
||||
.WhereIf(false, a => b.ParentId == 20));
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a, \"TestTypeInfo\" b, \"TestTypeParentInfo\" c", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
@ -551,15 +520,25 @@ namespace FreeSql.Tests.Sqlite {
|
||||
}
|
||||
[Fact]
|
||||
public void OrderBy() {
|
||||
var sql = select.OrderBy(a => new Random().NextDouble()).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Skip_Offset() {
|
||||
var sql = select.Offset(10).Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Take_Limit() {
|
||||
var sql = select.Limit(10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Page() {
|
||||
var sql1 = select.Page(1, 10).ToList();
|
||||
var sql2 = select.Page(2, 10).ToList();
|
||||
var sql3 = select.Page(3, 10).ToList();
|
||||
|
||||
var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList();
|
||||
var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList();
|
||||
var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void Sum() {
|
||||
@ -614,7 +593,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).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 \"TestTypeParentInfoAsTable\" a__Type__Parent ON 1 = 1 LEFT JOIN \"TestTypeInfoAsTable2\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
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\" AND a__Type.\"Name\" = 'xxx' LEFT JOIN \"TestTypeParentInfoAsTable\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid).AsTable(tableRule);
|
||||
@ -625,9 +604,9 @@ namespace FreeSql.Tests.Sqlite {
|
||||
sql = query.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_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx'", sql);
|
||||
|
||||
query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
query = select.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
|
||||
sql = query.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_topic22AsTable1\" a LEFT JOIN \"TestTypeParentInfoAsTable\" b__Parent ON 1 = 1 LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TypeGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
|
||||
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\" AND a__Type.\"Name\" = 'xxx' LEFT JOIN \"TestTypeParentInfoAsTable\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\" WHERE (a__Type__Parent.\"Id\" = 10)", sql);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
query = select
|
||||
@ -637,10 +616,10 @@ namespace FreeSql.Tests.Sqlite {
|
||||
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\" LEFT JOIN \"TestTypeParentInfoAsTable\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\"", sql);
|
||||
|
||||
query = select
|
||||
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeInfo>((a, a__Type) => a__Type.Guid == a.TypeGuid)
|
||||
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
|
||||
sql = query.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_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TypeGuid\" LEFT JOIN \"TestTypeParentInfoAsTable\" c ON c.\"Id\" = b.\"ParentId\"", sql);
|
||||
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\" LEFT JOIN \"TestTypeParentInfoAsTable\" c ON c.\"Id\" = a__Type.\"ParentId\"", sql);
|
||||
|
||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
|
@ -21,6 +21,7 @@ namespace FreeSql.Tests.SqliteExpression {
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Tests.SqliteExpression {
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
|
@ -25,6 +25,13 @@ public class g {
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseSyncStructureToLower(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => {
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => {
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
.Build());
|
||||
public static IFreeSql pgsql => pgsqlLazy.Value;
|
||||
|
||||
@ -33,6 +40,15 @@ public class g {
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseSyncStructureToUpper(true)
|
||||
//.UseNoneCommandParameter(true)
|
||||
|
||||
.UseMonitorCommand(
|
||||
cmd => {
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => {
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
.Build());
|
||||
public static IFreeSql oracle = oracleLazy.Value;
|
||||
|
||||
@ -40,6 +56,13 @@ public class g {
|
||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => {
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => {
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
.Build());
|
||||
public static IFreeSql sqlite = sqliteLazy.Value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user