Skip to content

Commit

Permalink
- 增加 FreeSqlBuilder UseNameConvert 方法,类名、属性名都生效;
Browse files Browse the repository at this point in the history
- 调整 FreeSqlBuilder,准备移除 UseEntityPropertyNameConvert/UseSyncStructureToLower/UseSyncStructureToUpper 方法;#260
  • Loading branch information
28810 authored and 28810 committed Mar 30, 2020
1 parent bbe5450 commit f3593a3
Show file tree
Hide file tree
Showing 25 changed files with 232 additions and 95 deletions.
16 changes: 16 additions & 0 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions FreeSql.Tests/FreeSql.Tests.DbContext/g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class g
static Lazy<IFreeSql> pgsqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=10")
.UseAutoSyncStructure(true)
.UseSyncStructureToLower(true)
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
.UseLazyLoading(true)
.UseMonitorCommand(
cmd =>
Expand All @@ -63,7 +63,7 @@ public class g
.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
.UseAutoSyncStructure(true)
.UseLazyLoading(true)
.UseSyncStructureToUpper(true)
.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
.UseNoneCommandParameter(true)
.UseMonitorCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void ToList()
})
});
var ddd = g.mysql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
Assert.Equal(1, ddd.Count);
Assert.Single(ddd);
Assert.Equal(2, ddd[0].Childs.Count);
}
public class District
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ public void ExecuteAffrows()
{
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 100, 101, 102 }).ExecuteAffrows();
var odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") }).NoneParameter().OnDuplicateKeyUpdate();
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(100, 'title-100', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(100, 'title-100', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = VALUES(`time`)");
`time` = VALUES(`time`)", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

var odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 101, title = "title-101", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 102, title = "title-102", time = DateTime.Parse("2000-01-01") }
}).NoneParameter().OnDuplicateKeyUpdate();
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(100, 'title-100', '2000-01-01 00:00:00.000'), (101, 'title-101', '2000-01-01 00:00:00.000'), (102, 'title-102', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(100, 'title-100', '2000-01-01 00:00:00.000'), (101, 'title-101', '2000-01-01 00:00:00.000'), (102, 'title-102', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = VALUES(`time`)");
`time` = VALUES(`time`)", odku2.ToSql());
odku2.ExecuteAffrows();
}

Expand All @@ -44,45 +44,45 @@ public void IgnoreColumns()
{
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 200, 201, 202 }).ExecuteAffrows();
var odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().OnDuplicateKeyUpdate();
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = '2000-01-01 00:00:00.000'");
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

var odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") }
}).IgnoreColumns(a => a.time).NoneParameter().OnDuplicateKeyUpdate();
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = CASE `id`
WHEN 200 THEN '2000-01-01 00:00:00.000'
WHEN 201 THEN '2000-01-01 00:00:00.000'
WHEN 202 THEN '2000-01-01 00:00:00.000' END");
WHEN 202 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
odku2.ExecuteAffrows();


g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 200, 201, 202 }).ExecuteAffrows();
odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().OnDuplicateKeyUpdate().IgnoreColumns(a => a.title);
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200')
ON DUPLICATE KEY UPDATE
`time` = '2000-01-01 00:00:00.000'");
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") }
}).IgnoreColumns(a => a.time).NoneParameter().OnDuplicateKeyUpdate().IgnoreColumns(a => a.title);
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
ON DUPLICATE KEY UPDATE
`time` = CASE `id`
WHEN 200 THEN '2000-01-01 00:00:00.000'
WHEN 201 THEN '2000-01-01 00:00:00.000'
WHEN 202 THEN '2000-01-01 00:00:00.000' END");
WHEN 202 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
odku2.ExecuteAffrows();
}

Expand All @@ -91,45 +91,45 @@ public void UpdateColumns()
{
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 300, 301, 302 }).ExecuteAffrows();
var odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().OnDuplicateKeyUpdate();
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = '2000-01-01 00:00:00.000'");
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

var odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") }
}).InsertColumns(a => a.title).NoneParameter().OnDuplicateKeyUpdate();
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = CASE `id`
WHEN 300 THEN '2000-01-01 00:00:00.000'
WHEN 301 THEN '2000-01-01 00:00:00.000'
WHEN 302 THEN '2000-01-01 00:00:00.000' END");
WHEN 302 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
odku2.ExecuteAffrows();


g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 300, 301, 302 }).ExecuteAffrows();
odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().OnDuplicateKeyUpdate().UpdateColumns(a => a.time);
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300')
ON DUPLICATE KEY UPDATE
`time` = '2000-01-01 00:00:00.000'");
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") }
}).InsertColumns(a => a.title).NoneParameter().OnDuplicateKeyUpdate().UpdateColumns(a => a.time);
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
ON DUPLICATE KEY UPDATE
`time` = CASE `id`
WHEN 300 THEN '2000-01-01 00:00:00.000'
WHEN 301 THEN '2000-01-01 00:00:00.000'
WHEN 302 THEN '2000-01-01 00:00:00.000' END");
WHEN 302 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
odku2.ExecuteAffrows();
}

Expand All @@ -138,56 +138,56 @@ public void Set()
{
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
var odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().OnDuplicateKeyUpdate().Set(a => a.time, DateTime.Parse("2020-1-1"));
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`time` = '2020-01-01 00:00:00.000'");
`time` = '2020-01-01 00:00:00.000'", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

var odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
}).NoneParameter().OnDuplicateKeyUpdate().Set(a => a.time, DateTime.Parse("2020-1-1"));
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`time` = '2020-01-01 00:00:00.000'");
`time` = '2020-01-01 00:00:00.000'", odku2.ToSql());
odku2.ExecuteAffrows();


var dt2020 = DateTime.Parse("2020-1-1");
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().OnDuplicateKeyUpdate().Set(a => a.time == dt2020);
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`time` = '2020-01-01 00:00:00.000'");
`time` = '2020-01-01 00:00:00.000'", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
}).NoneParameter().OnDuplicateKeyUpdate().Set(a => a.time == dt2020);
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`time` = '2020-01-01 00:00:00.000'");
`time` = '2020-01-01 00:00:00.000'", odku2.ToSql());
odku2.ExecuteAffrows();


g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
odku1 = g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().OnDuplicateKeyUpdate().Set(a => new { time = dt2020, title = a.title + "123" });
Assert.Equal(odku1.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`time` = '2020-01-01 00:00:00.000', `title` = concat(`title`, '123')");
`time` = '2020-01-01 00:00:00.000', `title` = concat(`title`, '123')", odku1.ToSql());
Assert.Equal(1, odku1.ExecuteAffrows());

odku2 = g.mysql.Insert(new[] {
new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
new TestOnDuplicateKeyUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
}).NoneParameter().OnDuplicateKeyUpdate().Set(a => new { time = dt2020, title = a.title + "123" });
Assert.Equal(odku2.ToSql(), @"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
ON DUPLICATE KEY UPDATE
`time` = '2020-01-01 00:00:00.000', `title` = concat(`title`, '123')");
`time` = '2020-01-01 00:00:00.000', `title` = concat(`title`, '123')", odku2.ToSql());
odku2.ExecuteAffrows();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void ToList()
})
});
var ddd = g.dameng.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
Assert.Equal(1, ddd.Count);
Assert.Single(ddd);
Assert.Equal(2, ddd[0].Childs.Count);
}
public class District
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void ToList()
})
});
var ddd = g.odbc.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
Assert.Equal(1, ddd.Count);
Assert.Single(ddd);
Assert.Equal(2, ddd[0].Childs.Count);
}
public class District
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void ToList()
})
});
var ddd = g.mysql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
Assert.Equal(1, ddd.Count);
Assert.Single(ddd);
Assert.Equal(2, ddd[0].Childs.Count);
}
public class District
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void ToList()
})
});
var ddd = g.oracle.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
Assert.Equal(1, ddd.Count);
Assert.Single(ddd);
Assert.Equal(2, ddd[0].Childs.Count);
}
public class District
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void ToList()
})
});
var ddd = g.pgsql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
Assert.Equal(1, ddd.Count);
Assert.Single(ddd);
Assert.Equal(2, ddd[0].Childs.Count);
}
public class District
Expand Down
Loading

0 comments on commit f3593a3

Please sign in to comment.