mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 增加 IUpdate.SetSourceIgnore 方法,可实现忽略 null 属性的更新;
This commit is contained in:
parent
97d8c39e1a
commit
99f0dd7391
@ -72,7 +72,7 @@ namespace base_entity
|
|||||||
|
|
||||||
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
||||||
|
|
||||||
.UseMonitorCommand(cmd => Console.Write(cmd.CommandText))
|
.UseMonitorCommand(cmd => Console.WriteLine(cmd.CommandText))
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.Build();
|
.Build();
|
||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
|
@ -93,6 +93,20 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -73,6 +73,20 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -65,6 +65,20 @@ namespace FreeSql.Tests.Odbc.Default
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
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", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -93,6 +93,20 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -63,6 +63,20 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -64,6 +64,20 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -66,6 +66,20 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
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", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -73,6 +73,20 @@ namespace FreeSql.Tests.Dameng
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -75,6 +75,20 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
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", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -94,6 +94,20 @@ namespace FreeSql.Tests.MySql
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -63,6 +63,20 @@ namespace FreeSql.Tests.Oracle
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -63,7 +63,20 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
public int id2 { get; set; }
|
public int id2 { get; set; }
|
||||||
public string xx { 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]
|
[Fact]
|
||||||
public void IgnoreColumns()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,20 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
public int id2 { get; set; }
|
public int id2 { get; set; }
|
||||||
public string xx { 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]
|
[Fact]
|
||||||
public void IgnoreColumns()
|
public void IgnoreColumns()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,20 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
public string xx { get; set; }
|
public string xx { get; set; }
|
||||||
}
|
}
|
||||||
[Fact]
|
[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()
|
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", "");
|
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
@ -2048,30 +2048,44 @@
|
|||||||
<param name="source">实体集合</param>
|
<param name="source">实体集合</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.IUpdate`1.SetSourceIgnore(`0,System.Func{System.Object,System.Boolean})">
|
||||||
|
<summary>
|
||||||
|
更新数据,设置更新的实体,同时设置忽略的列<para></para>
|
||||||
|
忽略 null 属性:fsql.Update<T>().SetSourceAndIgnore(item, colval => colval == null)<para></para>
|
||||||
|
注意:参数 ignore 与 IUpdate.IgnoreColumns/UpdateColumns 不能同时使用
|
||||||
|
</summary>
|
||||||
|
<param name="source">实体</param>
|
||||||
|
<param name="ignore">属性值忽略判断, true忽略</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.IUpdate`1.IgnoreColumns(System.Linq.Expressions.Expression{System.Func{`0,System.Object}})">
|
<member name="M:FreeSql.IUpdate`1.IgnoreColumns(System.Linq.Expressions.Expression{System.Func{`0,System.Object}})">
|
||||||
<summary>
|
<summary>
|
||||||
忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})
|
忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})<para></para>
|
||||||
|
注意:不能与 UpdateColumns 不能同时使用
|
||||||
</summary>
|
</summary>
|
||||||
<param name="columns">lambda选择列</param>
|
<param name="columns">lambda选择列</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.IUpdate`1.IgnoreColumns(System.String[])">
|
<member name="M:FreeSql.IUpdate`1.IgnoreColumns(System.String[])">
|
||||||
<summary>
|
<summary>
|
||||||
忽略的列
|
忽略的列<para></para>
|
||||||
|
注意:不能与 UpdateColumns 不能同时使用
|
||||||
</summary>
|
</summary>
|
||||||
<param name="columns">属性名,或者字段名</param>
|
<param name="columns">属性名,或者字段名</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.IUpdate`1.UpdateColumns(System.Linq.Expressions.Expression{System.Func{`0,System.Object}})">
|
<member name="M:FreeSql.IUpdate`1.UpdateColumns(System.Linq.Expressions.Expression{System.Func{`0,System.Object}})">
|
||||||
<summary>
|
<summary>
|
||||||
指定的列,UpdateColumns(a => a.Name) | UpdateColumns(a => new{a.Name,a.Time}) | UpdateColumns(a => new[]{"name","time"})
|
指定的列,UpdateColumns(a => a.Name) | UpdateColumns(a => new{a.Name,a.Time}) | UpdateColumns(a => new[]{"name","time"})<para></para>
|
||||||
|
注意:不能与 IgnoreColumns 不能同时使用
|
||||||
</summary>
|
</summary>
|
||||||
<param name="columns">lambda选择列</param>
|
<param name="columns">lambda选择列</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.IUpdate`1.UpdateColumns(System.String[])">
|
<member name="M:FreeSql.IUpdate`1.UpdateColumns(System.String[])">
|
||||||
<summary>
|
<summary>
|
||||||
指定的列
|
指定的列<para></para>
|
||||||
|
注意:不能与 IgnoreColumns 同时使用
|
||||||
</summary>
|
</summary>
|
||||||
<param name="columns">属性名,或者字段名</param>
|
<param name="columns">属性名,或者字段名</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
|
@ -250,15 +250,9 @@ namespace FreeSql
|
|||||||
ret.CodeFirst.IsLazyLoading = _isLazyLoading;
|
ret.CodeFirst.IsLazyLoading = _isLazyLoading;
|
||||||
|
|
||||||
if (_aopCommandExecuting != null)
|
if (_aopCommandExecuting != null)
|
||||||
ret.Aop.CommandBefore += new EventHandler<Aop.CommandBeforeEventArgs>((s, e) =>
|
ret.Aop.CommandBefore += new EventHandler<Aop.CommandBeforeEventArgs>((s, e) => _aopCommandExecuting?.Invoke(e.Command));
|
||||||
{
|
|
||||||
_aopCommandExecuting?.Invoke(e.Command);
|
|
||||||
});
|
|
||||||
if (_aopCommandExecuted != null)
|
if (_aopCommandExecuted != null)
|
||||||
ret.Aop.CommandAfter += new EventHandler<Aop.CommandAfterEventArgs>((s, e) =>
|
ret.Aop.CommandAfter += new EventHandler<Aop.CommandAfterEventArgs>((s, e) => _aopCommandExecuted?.Invoke(e.Command, e.Log));
|
||||||
{
|
|
||||||
_aopCommandExecuted?.Invoke(e.Command, e.Log);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.EntityPropertyNameConvert(ret);
|
this.EntityPropertyNameConvert(ret);
|
||||||
//添加实体属性名全局AOP转换处理
|
//添加实体属性名全局AOP转换处理
|
||||||
|
@ -57,28 +57,41 @@ namespace FreeSql
|
|||||||
/// <param name="source">实体集合</param>
|
/// <param name="source">实体集合</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdate<T1> SetSource(IEnumerable<T1> source);
|
IUpdate<T1> SetSource(IEnumerable<T1> source);
|
||||||
|
/// <summary>
|
||||||
|
/// 更新数据,设置更新的实体,同时设置忽略的列<para></para>
|
||||||
|
/// 忽略 null 属性:fsql.Update<T>().SetSourceAndIgnore(item, colval => colval == null)<para></para>
|
||||||
|
/// 注意:参数 ignore 与 IUpdate.IgnoreColumns/UpdateColumns 不能同时使用
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">实体</param>
|
||||||
|
/// <param name="ignore">属性值忽略判断, true忽略</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IUpdate<T1> SetSourceIgnore(T1 source, Func<object, bool> ignore);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})
|
/// 忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})<para></para>
|
||||||
|
/// 注意:不能与 UpdateColumns 不能同时使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="columns">lambda选择列</param>
|
/// <param name="columns">lambda选择列</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdate<T1> IgnoreColumns(Expression<Func<T1, object>> columns);
|
IUpdate<T1> IgnoreColumns(Expression<Func<T1, object>> columns);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 忽略的列
|
/// 忽略的列<para></para>
|
||||||
|
/// 注意:不能与 UpdateColumns 不能同时使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="columns">属性名,或者字段名</param>
|
/// <param name="columns">属性名,或者字段名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdate<T1> IgnoreColumns(string[] columns);
|
IUpdate<T1> IgnoreColumns(string[] columns);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 指定的列,UpdateColumns(a => a.Name) | UpdateColumns(a => new{a.Name,a.Time}) | UpdateColumns(a => new[]{"name","time"})
|
/// 指定的列,UpdateColumns(a => a.Name) | UpdateColumns(a => new{a.Name,a.Time}) | UpdateColumns(a => new[]{"name","time"})<para></para>
|
||||||
|
/// 注意:不能与 IgnoreColumns 不能同时使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="columns">lambda选择列</param>
|
/// <param name="columns">lambda选择列</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdate<T1> UpdateColumns(Expression<Func<T1, object>> columns);
|
IUpdate<T1> UpdateColumns(Expression<Func<T1, object>> columns);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 指定的列
|
/// 指定的列<para></para>
|
||||||
|
/// 注意:不能与 IgnoreColumns 同时使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="columns">属性名,或者字段名</param>
|
/// <param name="columns">属性名,或者字段名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
@ -55,7 +55,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
if (_table == null || _table.Type == typeof(object)) return;
|
if (_table == null || _table.Type == typeof(object)) return;
|
||||||
foreach (var col in _table.Columns.Values)
|
foreach (var col in _table.Columns.Values)
|
||||||
if (col.Attribute.CanUpdate == false)
|
if (col.Attribute.CanUpdate == false && _ignore.ContainsKey(col.Attribute.Name) == false)
|
||||||
_ignore.Add(col.Attribute.Name, true);
|
_ignore.Add(col.Attribute.Name, true);
|
||||||
}
|
}
|
||||||
protected void ClearData()
|
protected void ClearData()
|
||||||
@ -375,6 +375,16 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_source.AddRange(source.Where(a => a != null));
|
_source.AddRange(source.Where(a => a != null));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public IUpdate<T1> SetSourceIgnore(T1 source, Func<object, bool> ignore)
|
||||||
|
{
|
||||||
|
if (ignore == null) throw new ArgumentNullException(nameof(ignore));
|
||||||
|
var columns = _table.Columns.Values
|
||||||
|
.Where(col => ignore(_orm.GetEntityValueWithPropertyName(_table.Type, source, col.CsName)))
|
||||||
|
.Select(col => col.Attribute.Name).ToArray();
|
||||||
|
IgnoreColumns(columns);
|
||||||
|
IgnoreCanUpdate();
|
||||||
|
return SetSource(source);
|
||||||
|
}
|
||||||
|
|
||||||
protected void SetPriv(ColumnInfo col, object value)
|
protected void SetPriv(ColumnInfo col, object value)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user