From 21198be8335115207a4e0452d6958a95bb4afcf0 Mon Sep 17 00:00:00 2001 From: SW Date: Tue, 11 Jun 2024 18:49:22 +0800 Subject: [PATCH] fix error when StorageableByObject(null) or StorageableByObject(new List()) --- .../Abstract/SaveableProvider/StorageableMethodInfo.cs | 7 ++++--- Src/Asp.NetCore2/SqliteTest/9_Update.cs | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/SaveableProvider/StorageableMethodInfo.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/SaveableProvider/StorageableMethodInfo.cs index 1ee68910c..559718d05 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/SaveableProvider/StorageableMethodInfo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/SaveableProvider/StorageableMethodInfo.cs @@ -111,9 +111,9 @@ namespace SqlSugar } public StorageableCommonMethodInfo IgnoreColumns(params string[] ignoreColumns) { - PropertyInfo property = ObjectValue.GetType().GetProperty(type); - var value = property.GetValue(ObjectValue); - var newObj = value.GetType().GetMyMethod("IgnoreColumns", 1, typeof(string[])).Invoke(value, new object[] { ignoreColumns }); + PropertyInfo property = ObjectValue?.GetType().GetProperty(type); + var value = property?.GetValue(ObjectValue); + var newObj = value?.GetType().GetMyMethod("IgnoreColumns", 1, typeof(string[])).Invoke(value, new object[] { ignoreColumns }); StorageableCommonMethodInfo result = new StorageableCommonMethodInfo(); result.Value = newObj; return result; @@ -124,6 +124,7 @@ namespace SqlSugar public object Value { get; set; } public int ExecuteCommand() { + if(Value == null) return 0; var newObj = Value.GetType().GetMethod("ExecuteCommand").Invoke(Value, new object[] { }); return (int)newObj; } diff --git a/Src/Asp.NetCore2/SqliteTest/9_Update.cs b/Src/Asp.NetCore2/SqliteTest/9_Update.cs index ab3e9f2b5..6a48ec517 100644 --- a/Src/Asp.NetCore2/SqliteTest/9_Update.cs +++ b/Src/Asp.NetCore2/SqliteTest/9_Update.cs @@ -52,7 +52,10 @@ namespace OrmTest // 忽略为NULL和默认值的列进行更新(Ignore columns with NULL and default values during update) var result7 = db.Updateable(updateObj) - .IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue:true) + .IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue: true) + .ExecuteCommand(); + var result7a = db.StorageableByObject(new List()).ToStorage().AsUpdateable + .IgnoreColumns(new[] { "" }) .ExecuteCommand(); // 使用最快的方式批量更新实体对象列表(Bulk update a list of entity objects using the fastest method)