- 增加 IUpdate.SetSourceIgnore 方法,可实现忽略 null 属性的更新;

This commit is contained in:
28810
2020-05-22 18:20:28 +08:00
parent 97d8c39e1a
commit 99f0dd7391
19 changed files with 246 additions and 21 deletions

View File

@ -93,6 +93,20 @@ namespace FreeSql.Tests.MySqlConnector
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE `tssi01` SET `tint` = 10 WHERE (`id` = '00000000-0000-0000-0000-000000000000')",
g.mysql.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -73,6 +73,20 @@ namespace FreeSql.Tests.Odbc.Dameng
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')",
g.dameng.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -65,6 +65,20 @@ namespace FreeSql.Tests.Odbc.Default
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE [tssi01] SET [tint] = 10 WHERE ([id] = '00000000-0000-0000-0000-000000000000')",
g.odbc.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");

View File

@ -93,6 +93,20 @@ namespace FreeSql.Tests.Odbc.MySql
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE `tssi01` SET `tint` = 10 WHERE (`id` = '00000000-0000-0000-0000-000000000000')",
g.mysql.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -63,6 +63,20 @@ namespace FreeSql.Tests.Odbc.Oracle
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')",
g.oracle.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -64,6 +64,20 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"tssi01\" SET \"tint\" = 10 WHERE (\"id\" = '00000000-0000-0000-0000-000000000000')",
g.pgsql.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -66,6 +66,20 @@ namespace FreeSql.Tests.Odbc.SqlServer
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE [tssi01] SET [tint] = 10 WHERE ([id] = '00000000-0000-0000-0000-000000000000')",
g.sqlserver.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");

View File

@ -73,6 +73,20 @@ namespace FreeSql.Tests.Dameng
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')",
g.dameng.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -75,6 +75,20 @@ namespace FreeSql.Tests.MsAccess
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE [tssi01] SET [tint] = 10 WHERE ([id] = '00000000-0000-0000-0000-000000000000')",
g.msaccess.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");

View File

@ -94,6 +94,20 @@ namespace FreeSql.Tests.MySql
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE `tssi01` SET `tint` = 10 WHERE (`id` = '00000000-0000-0000-0000-000000000000')",
g.mysql.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -63,6 +63,20 @@ namespace FreeSql.Tests.Oracle
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')",
g.oracle.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");

View File

@ -63,7 +63,20 @@ namespace FreeSql.Tests.PostgreSQL
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"tssi01\" SET \"tint\" = 10 WHERE (\"id\" = '00000000-0000-0000-0000-000000000000')",
g.pgsql.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{

View File

@ -74,7 +74,20 @@ namespace FreeSql.Tests.SqlServer
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE [tssi01] SET [tint] = 10 WHERE ([id] = '00000000-0000-0000-0000-000000000000')",
g.sqlserver.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{

View File

@ -65,6 +65,20 @@ namespace FreeSql.Tests.Sqlite
public string xx { get; set; }
}
[Fact]
public void SetSourceIgnore()
{
Assert.Equal("UPDATE \"tssi01\" SET \"tint\" = 10 WHERE (\"id\" = '00000000-0000-0000-0000-000000000000')",
g.sqlite.Update<tssi01>().NoneParameter()
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
}
public class tssi01
{
[Column(CanUpdate = false)]
public Guid id { get; set; }
public int tint { get; set; }
public string title { get; set; }
}
[Fact]
public void IgnoreColumns()
{
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");