This commit is contained in:
sunkaixuan 2017-05-14 12:59:15 +08:00
parent 0260337376
commit fefa1d6ea1
7 changed files with 95 additions and 5 deletions

View File

@ -25,9 +25,9 @@ namespace OrmTest
//use lock //use lock
var s2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql(); var s2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
//by primary key //by primary key
var s3 = db.Deleteable<Student>().Where(1).ToSql(); var s3 = db.Deleteable<Student>().In(1).ToSql();
//by primary key array //by primary key array
var s4 = db.Deleteable<Student>().Where(new int[] { 1,2}).ToSql(); var s4 = db.Deleteable<Student>().In(new int[] { 1,2}).ToSql();
//by expression //by expression
var s5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql(); var s5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql();
} }

View File

@ -7,6 +7,8 @@ namespace SqlSugar
{ {
public class UpdateBuilder : IDMLBuilder public class UpdateBuilder : IDMLBuilder
{ {
public ISqlBuilder Builder { get; internal set; }
public SqlSugarClient Context public SqlSugarClient Context
{ {
get get
@ -20,6 +22,8 @@ namespace SqlSugar
} }
} }
public ILambdaExpressions LambdaExpressions { get; internal set; }
public List<SugarParameter> Parameters public List<SugarParameter> Parameters
{ {
get get

View File

@ -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<T> : IUpdateable<T>
{
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<T> IgnoreColumns(Expression<Func<T, object[]>> columns)
{
throw new NotImplementedException();
}
public IInsertable<T> Update(T InsertObj)
{
throw new NotImplementedException();
}
public IInsertable<T> UpdateColumns(Expression<Func<T, object[]>> columns)
{
throw new NotImplementedException();
}
public IInsertable<T> UpdateRange(List<T> InsertObjs)
{
throw new NotImplementedException();
}
public IInsertable<T> Where(bool isUpdateNull)
{
throw new NotImplementedException();
}
public IInsertable<T> With(string lockString)
{
throw new NotImplementedException();
}
internal void Init()
{
throw new NotImplementedException();
}
}
}

View File

@ -31,6 +31,12 @@ namespace SqlSugar
InsertBuilder reval = CreateInstance<InsertBuilder>(GetClassName(currentConnectionConfig.DbType, "InsertBuilder"), currentConnectionConfig.DbType); InsertBuilder reval = CreateInstance<InsertBuilder>(GetClassName(currentConnectionConfig.DbType, "InsertBuilder"), currentConnectionConfig.DbType);
return reval; return reval;
} }
public static UpdateBuilder GetUpdateBuilder(IConnectionConfig currentConnectionConfig)
{
CheckConfig(currentConnectionConfig);
UpdateBuilder reval = CreateInstance<UpdateBuilder>(GetClassName(currentConnectionConfig.DbType, "UpdateBuilder"), currentConnectionConfig.DbType);
return reval;
}
public static DeleteBuilder GetDeleteBuilder(IConnectionConfig currentConnectionConfig) public static DeleteBuilder GetDeleteBuilder(IConnectionConfig currentConnectionConfig)
{ {
CheckConfig(currentConnectionConfig); CheckConfig(currentConnectionConfig);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace SqlSugar namespace SqlSugar
{ {
public interface IDeleteable<T> public interface IDeleteable<T> where T : class, new()
{ {
int ExecuteCommand(); int ExecuteCommand();
IDeleteable<T> With(string lockString); IDeleteable<T> With(string lockString);

View File

@ -56,6 +56,7 @@
<Compile Include="Abstract\DbProvider\EntityProvider\EntityProvider.cs" /> <Compile Include="Abstract\DbProvider\EntityProvider\EntityProvider.cs" />
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" /> <Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" /> <Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
<Compile Include="Databases\SqlServer\Db\SqlBuilder\SqlServerInsertBuilder.cs" /> <Compile Include="Databases\SqlServer\Db\SqlBuilder\SqlServerInsertBuilder.cs" />
<Compile Include="Entities\EntityColumnInfo.cs" /> <Compile Include="Entities\EntityColumnInfo.cs" />
<Compile Include="Entities\EntityInfo.cs" /> <Compile Include="Entities\EntityInfo.cs" />
@ -161,7 +162,6 @@
<Content Include="Lib\Newtonsoft.Json.dll" /> <Content Include="Lib\Newtonsoft.Json.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Abstract\UpdateProvider\" />
<Folder Include="Databases\MySql\" /> <Folder Include="Databases\MySql\" />
<Folder Include="Databases\Oracle\" /> <Folder Include="Databases\Oracle\" />
<Folder Include="Databases\Sqlite\" /> <Folder Include="Databases\Sqlite\" />

View File

@ -274,6 +274,28 @@ namespace SqlSugar
} }
#endregion #endregion
#region Updateable
public virtual IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new()
{
var reval = new UpdateableProvider<T>();
var sqlBuilder = InstanceFactory.GetSqlbuilder(base.CurrentConnectionConfig); ;
reval.Context = this;
reval.EntityInfo = this.EntityProvider.GetEntityInfo<T>();
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<T> Updateable<T>(T UpdateObj) where T : class, new()
{
return this.Updateable(new T[] { UpdateObj });
}
#endregion
#region SqlQuery #region SqlQuery
public virtual List<T> SqlQuery<T>(string sql, object whereObj = null) public virtual List<T> SqlQuery<T>(string sql, object whereObj = null)
{ {