- 修复 GroupBy 类型转换错误;#186

- 修复 .ToList(a => new DTO(a.id)) 报 未将对象引用设置到对象的实例 问题; #187
- 修复 update语句,二元运算解析出错; #184
This commit is contained in:
28810 2020-01-19 23:53:06 +08:00
parent 774511e7ec
commit c64deb3d20
33 changed files with 428 additions and 9 deletions

View File

@ -155,6 +155,19 @@ namespace FreeSql.Tests.MySqlConnector
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()
{
@ -171,6 +184,18 @@ namespace FreeSql.Tests.MySqlConnector
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();
@ -735,6 +760,9 @@ namespace FreeSql.Tests.MySqlConnector
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

View File

@ -128,6 +128,10 @@ namespace FreeSql.Tests.MySqlConnector
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);

View File

@ -146,6 +146,19 @@ namespace FreeSql.Tests.Odbc.Dameng
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()
{
@ -160,6 +173,18 @@ namespace FreeSql.Tests.Odbc.Dameng
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);
@ -662,6 +687,9 @@ namespace FreeSql.Tests.Odbc.Dameng
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

View File

@ -86,6 +86,10 @@ namespace FreeSql.Tests.Odbc.Dameng
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);
}

View File

@ -137,6 +137,19 @@ namespace FreeSql.Tests.Odbc.Default
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()
{
@ -151,6 +164,18 @@ namespace FreeSql.Tests.Odbc.Default
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);
@ -653,6 +678,9 @@ namespace FreeSql.Tests.Odbc.Default
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

View File

@ -88,6 +88,10 @@ namespace FreeSql.Tests.Odbc.Default
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);
}

View File

@ -155,6 +155,19 @@ namespace FreeSql.Tests.Odbc.MySql
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()
{
@ -171,6 +184,18 @@ namespace FreeSql.Tests.Odbc.MySql
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();
@ -746,6 +771,9 @@ namespace FreeSql.Tests.Odbc.MySql
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

View File

@ -128,6 +128,10 @@ namespace FreeSql.Tests.Odbc.MySql
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);

View File

@ -146,6 +146,19 @@ namespace FreeSql.Tests.Odbc.Oracle
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()
{
@ -160,6 +173,18 @@ namespace FreeSql.Tests.Odbc.Oracle
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);
@ -662,6 +687,9 @@ namespace FreeSql.Tests.Odbc.Oracle
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

View File

@ -86,6 +86,10 @@ namespace FreeSql.Tests.Odbc.Oracle
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);
}

View File

@ -136,6 +136,19 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
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()
{
@ -150,6 +163,17 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
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();
@ -724,6 +748,9 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
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

View File

@ -87,6 +87,10 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
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.000000' 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);
}

View File

@ -137,6 +137,19 @@ namespace FreeSql.Tests.Odbc.SqlServer
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()
{
@ -150,6 +163,18 @@ namespace FreeSql.Tests.Odbc.SqlServer
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.sqlserver.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.sqlserver.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.sqlserver.Select<TestGuidIdToList>().ToList(a => a.id);
@ -618,6 +643,9 @@ namespace FreeSql.Tests.Odbc.SqlServer
var testpid1 = g.sqlserver.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.sqlserver.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

View File

@ -89,6 +89,10 @@ namespace FreeSql.Tests.Odbc.SqlServer
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.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);
}

View File

@ -137,6 +137,19 @@ namespace FreeSql.Tests.MsAccess
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()
{
@ -151,6 +164,18 @@ namespace FreeSql.Tests.MsAccess
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.msaccess.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.msaccess.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.msaccess.Select<TestGuidIdToList>().ToList(a => a.id);
@ -651,6 +676,9 @@ namespace FreeSql.Tests.MsAccess
var testpid1 = g.msaccess.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.msaccess.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

View File

@ -88,6 +88,10 @@ namespace FreeSql.Tests.MsAccess
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] = iif([CreateTime] > '2000-01-01 00:00:00', 1, 2) 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);
}

View File

@ -155,6 +155,19 @@ namespace FreeSql.Tests.MySql
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()
{
@ -171,6 +184,18 @@ namespace FreeSql.Tests.MySql
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();
@ -777,6 +802,9 @@ namespace FreeSql.Tests.MySql
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

View File

@ -129,6 +129,10 @@ namespace FreeSql.Tests.MySql
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);

View File

@ -146,6 +146,19 @@ namespace FreeSql.Tests.Oracle
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()
{
@ -160,6 +173,18 @@ namespace FreeSql.Tests.Oracle
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);
@ -662,6 +687,9 @@ namespace FreeSql.Tests.Oracle
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

View File

@ -86,6 +86,10 @@ namespace FreeSql.Tests.Oracle
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);
}

View File

@ -136,6 +136,19 @@ namespace FreeSql.Tests.PostgreSQL
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()
{
@ -150,6 +163,17 @@ namespace FreeSql.Tests.PostgreSQL
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();
@ -741,6 +765,9 @@ namespace FreeSql.Tests.PostgreSQL
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

View File

@ -87,6 +87,10 @@ namespace FreeSql.Tests.PostgreSQL
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.000000' 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);
}

View File

@ -147,6 +147,19 @@ namespace FreeSql.Tests.SqlServer
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()
{
@ -160,6 +173,18 @@ namespace FreeSql.Tests.SqlServer
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.sqlserver.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.sqlserver.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.sqlserver.Select<TestGuidIdToList>().ToList(a => a.id);
@ -666,6 +691,9 @@ namespace FreeSql.Tests.SqlServer
var testpid1 = g.sqlserver.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.sqlserver.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

View File

@ -98,6 +98,10 @@ namespace FreeSql.Tests.SqlServer
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.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);
}

View File

@ -146,6 +146,19 @@ namespace FreeSql.Tests.Sqlite
public TestDtoLeftJoin Obj { get; set; }
}
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;
}
}
class TestDtoLeftJoin
{
[Column(IsPrimary = true)]
@ -177,6 +190,18 @@ namespace FreeSql.Tests.Sqlite
var testDto33 = select.LeftJoin<TestDtoLeftJoin>((a, b) => b.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin<TestDtoLeftJoin>((a, b) => b.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.sqlite.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.sqlite.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.sqlite.Select<TestGuidIdToList>().ToList(a => a.id);
@ -615,6 +640,9 @@ namespace FreeSql.Tests.Sqlite
var testpid1 = g.sqlite.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
g.sqlite.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

View File

@ -91,6 +91,10 @@ namespace FreeSql.Tests.Sqlite
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);
}

View File

@ -698,7 +698,7 @@ namespace FreeSql.Tests
.ToSql(a => new NewsArticleDto
{
ArticleTitle = a.Key,
ChannelId = a.Sum(a.Value.Item1.OptionsEntity04)
ChannelId = (int)a.Sum(a.Value.Item1.OptionsEntity04)
});
var testgrpsql2 = g.sqlite.Select<TaskBuild>()

View File

@ -127,14 +127,14 @@ namespace FreeSql
/// <typeparam name="T3"></typeparam>
/// <param name="column"></param>
/// <returns></returns>
T3 Sum<T3>(T3 column);
decimal Sum<T3>(T3 column);
/// <summary>
/// 平均值
/// </summary>
/// <typeparam name="T3"></typeparam>
/// <param name="column"></param>
/// <returns></returns>
T3 Avg<T3>(T3 column);
decimal Avg<T3>(T3 column);
/// <summary>
/// 最大值
/// </summary>

View File

@ -124,7 +124,7 @@ namespace FreeSql.Internal
var child = new ReadAnonymousTypeInfo
{
Property = null,
CsName = (initExp.NewExpression.Arguments[a] as MemberExpression)?.Member.Name,
CsName = initExp.NewExpression.Members != null ? initExp.NewExpression.Members[a].Name : (initExp.NewExpression.Arguments[a] as MemberExpression)?.Member.Name,
CsType = initExp.NewExpression.Arguments[a].Type,
MapType = initExp.NewExpression.Arguments[a].Type
};
@ -206,7 +206,7 @@ namespace FreeSql.Internal
var child = new ReadAnonymousTypeInfo
{
Property = null,
CsName = (newExp.Arguments[a] as MemberExpression)?.Member.Name,
CsName = newExp.Members != null ? newExp.Members[a].Name : (newExp.Arguments[a] as MemberExpression)?.Member.Name,
CsType = newExp.Arguments[a].Type,
MapType = newExp.Arguments[a].Type
};

View File

@ -114,6 +114,7 @@ namespace FreeSql.Internal.CommonProvider
var index = 0;
_comonExp.ReadAnonymousField(null, field, map, ref index, select, getSelectGroupingMapString, null, true);
if (map.Childs.Any() == false && map.MapType == null) map.MapType = typeof(TReturn);
var method = _select.GetType().GetMethod("ToListMapReader", BindingFlags.Instance | BindingFlags.NonPublic);
method = method.MakeGenericMethod(typeof(TReturn));
return method.Invoke(_select, new object[] { (map, field.Length > 0 ? field.Remove(0, 2).ToString() : null) }) as List<TReturn>;
@ -181,6 +182,7 @@ namespace FreeSql.Internal.CommonProvider
var index = 0;
_comonExp.ReadAnonymousField(null, field, map, ref index, select, getSelectGroupingMapString, null, true);
if (map.Childs.Any() == false && map.MapType == null) map.MapType = typeof(TReturn);
var method = _select.GetType().GetMethod("ToListMapReaderAsync", BindingFlags.Instance | BindingFlags.NonPublic);
method = method.MakeGenericMethod(typeof(TReturn));
return method.Invoke(_select, new object[] { (map, field.Length > 0 ? field.Remove(0, 2).ToString() : null) }) as Task<List<TReturn>>;

View File

@ -363,7 +363,9 @@ namespace FreeSql.Internal.CommonProvider
switch (nodeType)
{
case ExpressionType.Equal:
_set.Append(", ").Append(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp, null, null));
var equalBinaryExp = body as BinaryExpression;
_set.Append(", ").Append(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, equalBinaryExp.Left, null, null))
.Append(" = ").Append(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, equalBinaryExp.Right, null, null));
return this;
case ExpressionType.MemberInit:
var initExp = body as MemberInitExpression;

View File

@ -160,7 +160,7 @@ namespace FreeSql.Sqlite
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
var tbtmp = tboldname ?? tbname;
var dsql = _orm.Ado.ExecuteScalar(CommandType.Text, $" select sql from {tbtmp[0]}.sqlite_master where type='table' and name='{tbtmp[1]}'")?.ToString();
var ds = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.table_info({_commonUtils.QuoteSqlName(tbtmp[1])})");
var ds = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.table_info(\"{tbtmp[1]}\")");
var tbstruct = ds.ToDictionary(a => string.Concat(a[1]), a =>
{
var is_identity = false;
@ -202,7 +202,7 @@ namespace FreeSql.Sqlite
istmpatler = true;
}
var dsuk = new List<string[]>();
var dbIndexes = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.INDEX_LIST({_commonUtils.QuoteSqlName(tbtmp[1])})");
var dbIndexes = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.INDEX_LIST(\"{tbtmp[1]}\")");
foreach (var dbIndex in dbIndexes)
{
if (string.Concat(dbIndex[3]) == "pk") continue;

View File

@ -279,6 +279,7 @@ Elapsed: 00:00:00.6495301; Query Entity Counts: 131072; ORM: Dapper
深圳|凉茶、
[densen2014](https://github.com/densen2014)、
[LiaoLiaoWuJu](https://github.com/LiaoLiaoWuJu)、
[hd2y](https://github.com/hd2y)
[hd2y](https://github.com/hd2y)、
[tky753](https://github.com/tky753)
QQ群4336577