diff --git a/OrmTest/UnitTest/Delete.cs b/OrmTest/UnitTest/Delete.cs index e7bbe8eb7..f925bd9ed 100644 --- a/OrmTest/UnitTest/Delete.cs +++ b/OrmTest/UnitTest/Delete.cs @@ -25,9 +25,9 @@ namespace OrmTest //use lock var s2 = db.Deleteable().With(SqlWith.RowLock).ToSql(); //by primary key - var s3 = db.Deleteable().Where(1).ToSql(); + var s3 = db.Deleteable().In(1).ToSql(); //by primary key array - var s4 = db.Deleteable().Where(new int[] { 1,2}).ToSql(); + var s4 = db.Deleteable().In(new int[] { 1,2}).ToSql(); //by expression var s5 = db.Deleteable().Where(it=>it.Id==1).ToSql(); } diff --git a/SqlSugar/Abstract/DbProvider/SqlBuilderProvider/DMLBuilder/UpdateBuilder.cs b/SqlSugar/Abstract/DbProvider/SqlBuilderProvider/DMLBuilder/UpdateBuilder.cs index 2edf9b3ee..b27ca3b70 100644 --- a/SqlSugar/Abstract/DbProvider/SqlBuilderProvider/DMLBuilder/UpdateBuilder.cs +++ b/SqlSugar/Abstract/DbProvider/SqlBuilderProvider/DMLBuilder/UpdateBuilder.cs @@ -7,6 +7,8 @@ namespace SqlSugar { public class UpdateBuilder : IDMLBuilder { + public ISqlBuilder Builder { get; internal set; } + public SqlSugarClient Context { get @@ -20,6 +22,8 @@ namespace SqlSugar } } + public ILambdaExpressions LambdaExpressions { get; internal set; } + public List Parameters { get diff --git a/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs new file mode 100644 index 000000000..f865ed588 --- /dev/null +++ b/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace SqlSugar +{ + public class UpdateableProvider : IUpdateable + { + public SqlSugarClient Context { get; internal set; } + public EntityInfo EntityInfo { get; internal set; } + public ISqlBuilder SqlBuilder { get; internal set; } + public UpdateBuilder UpdateBuilder { get; internal set; } + public object[] UpdateObjs { get; internal set; } + + public int ExecuteCommand() + { + throw new NotImplementedException(); + } + + public IInsertable IgnoreColumns(Expression> columns) + { + throw new NotImplementedException(); + } + + public IInsertable Update(T InsertObj) + { + throw new NotImplementedException(); + } + + public IInsertable UpdateColumns(Expression> columns) + { + throw new NotImplementedException(); + } + + public IInsertable UpdateRange(List InsertObjs) + { + throw new NotImplementedException(); + } + + public IInsertable Where(bool isUpdateNull) + { + throw new NotImplementedException(); + } + + public IInsertable With(string lockString) + { + throw new NotImplementedException(); + } + + internal void Init() + { + throw new NotImplementedException(); + } + } +} diff --git a/SqlSugar/InstanceFactory.cs b/SqlSugar/InstanceFactory.cs index 9e58ceea9..3fbc4c269 100644 --- a/SqlSugar/InstanceFactory.cs +++ b/SqlSugar/InstanceFactory.cs @@ -31,6 +31,12 @@ namespace SqlSugar InsertBuilder reval = CreateInstance(GetClassName(currentConnectionConfig.DbType, "InsertBuilder"), currentConnectionConfig.DbType); return reval; } + public static UpdateBuilder GetUpdateBuilder(IConnectionConfig currentConnectionConfig) + { + CheckConfig(currentConnectionConfig); + UpdateBuilder reval = CreateInstance(GetClassName(currentConnectionConfig.DbType, "UpdateBuilder"), currentConnectionConfig.DbType); + return reval; + } public static DeleteBuilder GetDeleteBuilder(IConnectionConfig currentConnectionConfig) { CheckConfig(currentConnectionConfig); diff --git a/SqlSugar/Interface/IDeleteable.cs b/SqlSugar/Interface/IDeleteable.cs index 675a4bb82..d29d972fe 100644 --- a/SqlSugar/Interface/IDeleteable.cs +++ b/SqlSugar/Interface/IDeleteable.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace SqlSugar { - public interface IDeleteable + public interface IDeleteable where T : class, new() { int ExecuteCommand(); IDeleteable With(string lockString); @@ -15,7 +15,7 @@ namespace SqlSugar IDeleteable Where(Expression> expression); IDeleteable Where(List deleteObjs); IDeleteable In(PkType primaryKeyValue); - IDeleteable In(PkType [] primaryKeyValues); + IDeleteable In(PkType[] primaryKeyValues); IDeleteable Where(string whereString,object whereObj=null); KeyValuePair> ToSql(); } diff --git a/SqlSugar/SqlSugar.csproj b/SqlSugar/SqlSugar.csproj index cf71b69f5..6a55c8921 100644 --- a/SqlSugar/SqlSugar.csproj +++ b/SqlSugar/SqlSugar.csproj @@ -56,6 +56,7 @@ + @@ -161,7 +162,6 @@ - diff --git a/SqlSugar/SqlSugarClient.cs b/SqlSugar/SqlSugarClient.cs index 5a04cd757..46b85496c 100644 --- a/SqlSugar/SqlSugarClient.cs +++ b/SqlSugar/SqlSugarClient.cs @@ -274,6 +274,28 @@ namespace SqlSugar } #endregion + #region Updateable + public virtual IUpdateable Updateable(T[] UpdateObjs) where T : class, new() + { + var reval = new UpdateableProvider(); + var sqlBuilder = InstanceFactory.GetSqlbuilder(base.CurrentConnectionConfig); ; + reval.Context = this; + reval.EntityInfo = this.EntityProvider.GetEntityInfo(); + reval.SqlBuilder = sqlBuilder; + reval.UpdateObjs = UpdateObjs; + sqlBuilder.UpdateBuilder = reval.UpdateBuilder = InstanceFactory.GetUpdateBuilder(base.CurrentConnectionConfig); + sqlBuilder.UpdateBuilder.Builder = sqlBuilder; + sqlBuilder.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(base.CurrentConnectionConfig); + sqlBuilder.Context = reval.SqlBuilder.UpdateBuilder.Context = this; + reval.Init(); + return reval; + } + public virtual IUpdateable Updateable(T UpdateObj) where T : class, new() + { + return this.Updateable(new T[] { UpdateObj }); + } + #endregion + #region SqlQuery public virtual List SqlQuery(string sql, object whereObj = null) {