From e7a061b052c253c5729a85c7bd9ddbc9511b6251 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 25 Jul 2017 00:47:33 +0800 Subject: [PATCH] Insert update add dictionary Or dynamic Overloading of functions --- Src/Asp.Net/SqlSugar/SqlSugarClient.cs | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index a58579e07..172422d09 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -261,6 +261,24 @@ namespace SqlSugar { return this.Insertable(new T[] { insertObj }); } + public virtual IInsertable Insertable(Dictionary columnDictionary) where T : class, new() + { + Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null"); + var insertObject = this.RewritableMethods.DeserializeObject(this.RewritableMethods.SerializeObject(columnDictionary)); + return this.Insertable(insertObject); + } + public virtual IInsertable Insertable(dynamic insertDynamicObject) where T : class, new() + { + if (insertDynamicObject is T) + { + return this.Insertable((T)insertDynamicObject); + } + else + { + var insertObject = this.RewritableMethods.DeserializeObject(this.RewritableMethods.SerializeObject(insertDynamicObject)); + return this.Insertable(insertObject); + } + } #endregion #region Deleteable @@ -316,6 +334,24 @@ namespace SqlSugar { return this.Updateable(new T[] { new T() }); } + public virtual IUpdateable Updateable(Dictionary columnDictionary) where T : class, new() + { + Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null"); + var updateObject = this.RewritableMethods.DeserializeObject(this.RewritableMethods.SerializeObject(columnDictionary)); + return this.Updateable(updateObject); + } + public virtual IUpdateable Updateable(dynamic updateDynamicObject) where T : class, new() + { + if (updateDynamicObject is T) + { + return this.Updateable((T)updateDynamicObject); + } + else + { + var updateObject = this.RewritableMethods.DeserializeObject(this.RewritableMethods.SerializeObject(updateDynamicObject)); + return this.Updateable(updateObject); + } + } #endregion #region DbFirst