Skip to content

Commit

Permalink
- 修复 GroupBy 类型转换错误;#186
Browse files Browse the repository at this point in the history
- 修复 .ToList(a => new DTO(a.id)) 报 未将对象引用设置到对象的实例 问题; #187
- 修复 update语句,二元运算解析出错; #184
  • Loading branch information
28810 authored and 28810 committed Jan 19, 2020
1 parent 774511e commit c64deb3
Show file tree
Hide file tree
Showing 33 changed files with 428 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ class TestDto
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
class TestDto2
{
public int id { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性

public TestDto2() { }
public TestDto2(int id, string name)
{
this.id = id;
this.name = name;
}
}
[Fact]
public void ToList()
{
Expand All @@ -171,6 +184,18 @@ public void ToList()
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
var testDto55 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto>();

var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto212 = select.Limit(10).ToList(a => new TestDto2());
var testDto213 = select.Limit(10).ToList(a => new TestDto2 { });
var testDto214 = select.Limit(10).ToList(a => new TestDto2() { });
var testDto215 = select.Limit(10).ToList<TestDto2>();

var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2());
var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { });
var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { });
var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto2>();

var t0 = select.Limit(50).ToList();

var sql1 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).ToSql();
Expand Down Expand Up @@ -735,6 +760,9 @@ public void GroupBy()

var testpid1 = g.mysql.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();

var fkfjfj = select.GroupBy(a => a.Title)
.ToList(a => a.Sum(a.Value.TypeGuid));

var aggsql1 = select
.GroupBy(a => a.Title)
.ToSql(b => new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public void Set()

sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = `Clicks` * 10 div 1 WHERE (`Id` = 1)", sql);

var dt2000 = DateTime.Parse("2000-01-01");
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = case when `CreateTime` > '2000-01-01 00:00:00.000' then 1 else 2 end WHERE (`Id` = 1)", sql);

sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE `tb_topic` SET `Id` = 10 WHERE (`Id` = 1)", sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ class TestDto
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
class TestDto2
{
public int id { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性

public TestDto2() { }
public TestDto2(int id, string name)
{
this.id = id;
this.name = name;
}
}
[Fact]
public void ToList()
{
Expand All @@ -160,6 +173,18 @@ public void ToList()
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });

var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto212 = select.Limit(10).ToList(a => new TestDto2());
var testDto213 = select.Limit(10).ToList(a => new TestDto2 { });
var testDto214 = select.Limit(10).ToList(a => new TestDto2() { });
var testDto215 = select.Limit(10).ToList<TestDto2>();

var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2());
var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { });
var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { });
var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto2>();

g.dameng.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.dameng.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.dameng.Select<TestGuidIdToList>().ToList(a => a.id);
Expand Down Expand Up @@ -662,6 +687,9 @@ public void GroupBy()
var testpid1 = g.dameng.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.dameng.Insert<TestInfo>().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows();

var fkfjfj = select.GroupBy(a => a.Title)
.ToList(a => a.Sum(a.Value.TypeGuid));

var aggsql1 = select
.GroupBy(a => a.Title)
.ToSql(b => new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void Set()
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(\"CLICKS\" * 10 / 1) WHERE (\"ID\" = 1)", sql);

var dt2000 = DateTime.Parse("2000-01-01");
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = case when \"CREATETIME\" > to_timestamp('2000-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') then 1 else 2 end WHERE (\"ID\" = 1)", sql);

sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = 10 WHERE (\"ID\" = 1)", sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ class TestDto
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
class TestDto2
{
public int id { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性

public TestDto2() { }
public TestDto2(int id, string name)
{
this.id = id;
this.name = name;
}
}
[Fact]
public void ToList()
{
Expand All @@ -151,6 +164,18 @@ public void ToList()
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });

var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto212 = select.Limit(10).ToList(a => new TestDto2());
var testDto213 = select.Limit(10).ToList(a => new TestDto2 { });
var testDto214 = select.Limit(10).ToList(a => new TestDto2() { });
var testDto215 = select.Limit(10).ToList<TestDto2>();

var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2());
var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { });
var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { });
var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto2>();

g.odbc.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.odbc.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.odbc.Select<TestGuidIdToList>().ToList(a => a.id);
Expand Down Expand Up @@ -653,6 +678,9 @@ public void GroupBy()
var testpid1 = g.odbc.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.odbc.Insert<TestInfo>().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows();

var fkfjfj = select.GroupBy(a => a.Title)
.ToList(a => a.Sum(a.Value.TypeGuid));

var aggsql1 = select
.GroupBy(a => a.Title)
.ToSql(b => new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public void Set()
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = [Clicks] * 10 / 1 WHERE ([Id] = 1)", sql);

var dt2000 = DateTime.Parse("2000-01-01");
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = case when [CreateTime] > '2000-01-01 00:00:00' then 1 else 2 end WHERE ([Id] = 1)", sql);

sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [Id] = 10 WHERE ([Id] = 1)", sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ class TestDto
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
class TestDto2
{
public int id { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性

public TestDto2() { }
public TestDto2(int id, string name)
{
this.id = id;
this.name = name;
}
}
[Fact]
public void ToList()
{
Expand All @@ -171,6 +184,18 @@ public void ToList()
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
var testDto55 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto>();

var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto212 = select.Limit(10).ToList(a => new TestDto2());
var testDto213 = select.Limit(10).ToList(a => new TestDto2 { });
var testDto214 = select.Limit(10).ToList(a => new TestDto2() { });
var testDto215 = select.Limit(10).ToList<TestDto2>();

var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2());
var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { });
var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { });
var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto2>();

var t0 = select.Limit(50).ToList();


Expand Down Expand Up @@ -746,6 +771,9 @@ public void GroupBy()
var testpid1 = g.mysql.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.mysql.Insert<TestInfo>().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows();

var fkfjfj = select.GroupBy(a => a.Title)
.ToList(a => a.Sum(a.Value.TypeGuid));

var aggsql1 = select
.GroupBy(a => a.Title)
.ToSql(b => new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public void Set()
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = `Clicks` * 10 div 1 WHERE (`Id` = 1)", sql);

var dt2000 = DateTime.Parse("2000-01-01");
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = case when `CreateTime` > '2000-01-01 00:00:00.000' then 1 else 2 end WHERE (`Id` = 1)", sql);

sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE `tb_topic` SET `Id` = 10 WHERE (`Id` = 1)", sql);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ class TestDto
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
class TestDto2
{
public int id { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性

public TestDto2() { }
public TestDto2(int id, string name)
{
this.id = id;
this.name = name;
}
}
[Fact]
public void ToList()
{
Expand All @@ -160,6 +173,18 @@ public void ToList()
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });

var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto212 = select.Limit(10).ToList(a => new TestDto2());
var testDto213 = select.Limit(10).ToList(a => new TestDto2 { });
var testDto214 = select.Limit(10).ToList(a => new TestDto2() { });
var testDto215 = select.Limit(10).ToList<TestDto2>();

var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2());
var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { });
var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { });
var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto2>();

g.oracle.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.oracle.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.oracle.Select<TestGuidIdToList>().ToList(a => a.id);
Expand Down Expand Up @@ -662,6 +687,9 @@ public void GroupBy()
var testpid1 = g.oracle.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.oracle.Insert<TestInfo>().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows();

var fkfjfj = select.GroupBy(a => a.Title)
.ToList(a => a.Sum(a.Value.TypeGuid));

var aggsql1 = select
.GroupBy(a => a.Title)
.ToSql(b => new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void Set()
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(\"CLICKS\" * 10 / 1) WHERE (\"ID\" = 1)", sql);

var dt2000 = DateTime.Parse("2000-01-01");
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = case when \"CREATETIME\" > to_timestamp('2000-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') then 1 else 2 end WHERE (\"ID\" = 1)", sql);

sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = 10 WHERE (\"ID\" = 1)", sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ class TestDto
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
class TestDto2
{
public int id { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性

public TestDto2() { }
public TestDto2(int id, string name)
{
this.id = id;
this.name = name;
}
}
[Fact]
public void ToList()
{
Expand All @@ -150,6 +163,17 @@ public void ToList()
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });

var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto212 = select.Limit(10).ToList(a => new TestDto2());
var testDto213 = select.Limit(10).ToList(a => new TestDto2 { });
var testDto214 = select.Limit(10).ToList(a => new TestDto2() { });
var testDto215 = select.Limit(10).ToList<TestDto2>();

var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title));
var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2());
var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { });
var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { });
var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList<TestDto2>();

var t1 = g.pgsql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
var t2 = g.pgsql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
Expand Down Expand Up @@ -724,6 +748,9 @@ public void GroupBy()
var testpid1 = g.pgsql.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.pgsql.Insert<TestInfo>().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows();

var fkfjfj = select.GroupBy(a => a.Title)
.ToList(a => a.Sum(a.Value.TypeGuid));

var aggsql1 = select
.GroupBy(a => a.Title)
.ToSql(b => new
Expand Down
Loading

0 comments on commit c64deb3

Please sign in to comment.