Browse Source

Merge branch 'dev' of https://github.com/sunkaixuan/SqlSugar

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
161c074a37
  1. 21
      SqlServerTest/Demos/Filter.cs
  2. 3
      SqlServerTest/Demos/Update.cs
  3. 1
      SqlServerTest/SqlServerTest.csproj
  4. 2
      SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs
  5. 5
      SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs
  6. 40
      SqlSugar/Abstract/FilterProvider/FilterProvider.cs
  7. 6
      SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  8. 4
      SqlSugar/Abstract/SqlBuilderProvider/Detail/InsertBuilder.cs
  9. 6
      SqlSugar/Abstract/SqlBuilderProvider/Detail/UpdateBuilder.cs
  10. 3
      SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  11. 20
      SqlSugar/Entities/SqlFilter.cs
  12. 2
      SqlSugar/Interface/IUpdateable.cs
  13. 2
      SqlSugar/SqlSugar.csproj
  14. 1
      SqlSugar/SqlSugarAccessory.cs
  15. 19
      SqlSugar/SqlSugarClient.cs

21
SqlServerTest/Demos/Filter.cs

@ -0,0 +1,21 @@
using OrmTest.Demo;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demos
{
namespace OrmTest.Demo
{
public class Filter : DemoBase
{
public static void Init()
{
var db = GetInstance();
// db.QueryFilter.Add(eSqlFilterItem(){ });
}
}
}
}

3
SqlServerTest/Demos/Update.cs

@ -55,6 +55,9 @@ namespace OrmTest.Demo
//Rename //Rename
db.Updateable<School>().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommand(); db.Updateable<School>().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommand();
//Update Student set Name='jack' Where Id=1 //Update Student set Name='jack' Where Id=1
//Column is null no update
db.Updateable(updateObj).Where(true).ExecuteCommand();
} }
} }
} }

1
SqlServerTest/SqlServerTest.csproj

@ -48,6 +48,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="Demos\Filter.cs" />
<Compile Include="Demos\JoinSql.cs" /> <Compile Include="Demos\JoinSql.cs" />
<Compile Include="Demos\DbFirst.cs" /> <Compile Include="Demos\DbFirst.cs" />
<Compile Include="Demos\Delete.cs" /> <Compile Include="Demos\Delete.cs" />

2
SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs

@ -199,7 +199,7 @@ namespace SqlSugar
{ {
get get
{ {
return new List<string>() { "int32", "datetime", "decimal", "double", "byte", "string" }; return new List<string>() { "int32", "datetime", "decimal", "double", "byte" };
} }
} }
public virtual List<string> StringThrow public virtual List<string> StringThrow

5
SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs

@ -168,7 +168,8 @@ namespace SqlSugar
{ {
case CSharpDataType.@int: case CSharpDataType.@int:
CheckType(bind.IntThrow, bindProperyTypeName, validPropertyName, propertyName); CheckType(bind.IntThrow, bindProperyTypeName, validPropertyName, propertyName);
method = isNullableType ? getConvertInt32 : getInt32; if (bindProperyTypeName.IsContainsIn("int","int32","int64"))
method = isNullableType ? getConvertInt32 : getInt32;
break; break;
case CSharpDataType.@bool: case CSharpDataType.@bool:
if (bindProperyTypeName == "bool" || bindProperyTypeName == "boolean") if (bindProperyTypeName == "bool" || bindProperyTypeName == "boolean")
@ -220,7 +221,7 @@ namespace SqlSugar
method = getConvertString; method = getConvertString;
} }
if (method == null) if (method == null)
method = getOtherNull.MakeGenericMethod(bindPropertyType); method =isNullableType? getOtherNull.MakeGenericMethod(bindPropertyType):getOther.MakeGenericMethod(bindPropertyType);
generator.Emit(OpCodes.Call, method); generator.Emit(OpCodes.Call, method);
if (method == getValueMethod) if (method == getValueMethod)
{ {

40
SqlSugar/Abstract/FilterProvider/FilterProvider.cs

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class QueryFilterProvider
{
internal SqlSugarClient Context{ get; set; }
private List<SqlFilterItem> _Filters { get; set; }
public void Add(SqlFilterItem filter)
{
if (_Filters == null)
_Filters = new List<SqlFilterItem>();
}
public void Remove(string filterName)
{
if (_Filters == null)
_Filters = new List<SqlFilterItem>();
_Filters.RemoveAll(it => it.FilterName == filterName);
}
public List<SqlFilterItem> GeFilterList
{
get
{
if (_Filters == null)
_Filters = new List<SqlFilterItem>();
return _Filters;
}
}
public void Clear()
{
_Filters = new List<SqlFilterItem>();
}
}
}

6
SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -96,12 +96,12 @@ namespace SqlSugar
return this; return this;
} }
public IInsertable<T> Where(bool isInsertNull, bool isOffIdentity = false) public IInsertable<T> Where(bool isNoInsertNull, bool isOffIdentity = false)
{ {
this.IsOffIdentity = IsOffIdentity; this.IsOffIdentity = IsOffIdentity;
if (this.InsertBuilder.LambdaExpressions == null) if (this.InsertBuilder.LambdaExpressions == null)
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig); this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
this.InsertBuilder.IsInsertNull = isInsertNull; this.InsertBuilder.IsNoInsertNull = isNoInsertNull;
return this; return this;
} }
#endregion #endregion
@ -139,7 +139,7 @@ namespace SqlSugar
{ {
if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>(); if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>();
var paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType); var paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType);
if (InsertBuilder.IsInsertNull && paramters.Value == null) if (InsertBuilder.IsNoInsertNull && paramters.Value == null)
{ {
continue; continue;
} }

4
SqlSugar/Abstract/SqlBuilderProvider/Detail/InsertBuilder.cs

@ -21,7 +21,7 @@ namespace SqlSugar
public List<SugarParameter> Parameters { get; set; } public List<SugarParameter> Parameters { get; set; }
public string TableWithString { get; set; } public string TableWithString { get; set; }
public List<DbColumnInfo> DbColumnInfoList { get; set; } public List<DbColumnInfo> DbColumnInfoList { get; set; }
public bool IsInsertNull { get; set; } public bool IsNoInsertNull { get; set; }
public bool IsReturnIdentity { get; set; } public bool IsReturnIdentity { get; set; }
public EntityInfo EntityInfo { get; set; } public EntityInfo EntityInfo { get; set; }
@ -100,7 +100,7 @@ namespace SqlSugar
} }
public virtual string ToSqlString() public virtual string ToSqlString()
{ {
if (IsInsertNull) if (IsNoInsertNull)
{ {
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList(); DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList();
} }

6
SqlSugar/Abstract/SqlBuilderProvider/Detail/UpdateBuilder.cs

@ -26,7 +26,7 @@ namespace SqlSugar
public List<DbColumnInfo> DbColumnInfoList { get; set; } public List<DbColumnInfo> DbColumnInfoList { get; set; }
public List<string> WhereValues { get; set; } public List<string> WhereValues { get; set; }
public List<KeyValuePair<string, string>> SetValues { get; set; } public List<KeyValuePair<string, string>> SetValues { get; set; }
public bool IsUpdateNull { get; set; } public bool IsNoUpdateNull { get; set; }
public List<string> PrimaryKeys { get; set; } public List<string> PrimaryKeys { get; set; }
public bool IsOffIdentity { get; set; } public bool IsOffIdentity { get; set; }
@ -126,6 +126,10 @@ namespace SqlSugar
} }
public virtual string ToSqlString() public virtual string ToSqlString()
{ {
if (IsNoUpdateNull)
{
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList();
}
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList(); var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
var isSingle = groupList.Count() == 1; var isSingle = groupList.Count() == 1;
if (isSingle) if (isSingle)

3
SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -122,6 +122,9 @@ namespace SqlSugar
public IUpdateable<T> Where(bool isUpdateNull, bool IsOffIdentity = false) public IUpdateable<T> Where(bool isUpdateNull, bool IsOffIdentity = false)
{ {
UpdateBuilder.IsOffIdentity = IsOffIdentity; UpdateBuilder.IsOffIdentity = IsOffIdentity;
if (this.UpdateBuilder.LambdaExpressions == null)
this.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
this.UpdateBuilder.IsNoUpdateNull = isUpdateNull;
return this; return this;
} }
public IUpdateable<T> Where(Expression<Func<T, bool>> expression) public IUpdateable<T> Where(Expression<Func<T, bool>> expression)

20
SqlSugar/Entities/SqlFilter.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class SqlFilterItem
{
public string FilterName { get; set; }
public Func<SqlSugarClient,SqlFilterResult> GetFilterSql { get; set; }
public bool IsJoinQuery { get; set; }
}
public class SqlFilterResult
{
public string Sql { get; set; }
public List<SugarParameter> Parameters { get; set; }
}
}

2
SqlSugar/Interface/IUpdateable.cs

@ -12,7 +12,7 @@ namespace SqlSugar
int ExecuteCommand(); int ExecuteCommand();
IUpdateable<T> AS(string tableName); IUpdateable<T> AS(string tableName);
IUpdateable<T> With(string lockString); IUpdateable<T> With(string lockString);
IUpdateable<T> Where(bool isUpdateNull,bool IsOffIdentity = false); IUpdateable<T> Where(bool isNoUpdateNull,bool IsOffIdentity = false);
IUpdateable<T> Where(Expression<Func<T, bool>> expression); IUpdateable<T> Where(Expression<Func<T, bool>> expression);
IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns); IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns);
IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod); IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod);

2
SqlSugar/SqlSugar.csproj

@ -60,10 +60,12 @@
<Compile Include="Abstract\DbMaintenanceProvider\Properties.cs" /> <Compile Include="Abstract\DbMaintenanceProvider\Properties.cs" />
<Compile Include="Abstract\AdoProvider\AdoProvider.cs" /> <Compile Include="Abstract\AdoProvider\AdoProvider.cs" />
<Compile Include="Abstract\EntityProvider\EntityProvider.cs" /> <Compile Include="Abstract\EntityProvider\EntityProvider.cs" />
<Compile Include="Abstract\FilterProvider\FilterProvider.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="Abstract\UpdateProvider\UpdateableProvider.cs" />
<Compile Include="Entities\SchemaInfo.cs" /> <Compile Include="Entities\SchemaInfo.cs" />
<Compile Include="Entities\SqlFilter.cs" />
<Compile Include="Enum\DbObjectType.cs" /> <Compile Include="Enum\DbObjectType.cs" />
<Compile Include="Enum\ProperyType.cs" /> <Compile Include="Enum\ProperyType.cs" />
<Compile Include="ExpressionsToSql\Common\FileHeper.cs" /> <Compile Include="ExpressionsToSql\Common\FileHeper.cs" />

1
SqlSugar/SqlSugarAccessory.cs

@ -26,6 +26,7 @@ namespace SqlSugar
protected ILambdaExpressions _LambdaExpressions; protected ILambdaExpressions _LambdaExpressions;
protected IRewritableMethods _RewritableMethods; protected IRewritableMethods _RewritableMethods;
protected IDbMaintenance _DbMaintenance; protected IDbMaintenance _DbMaintenance;
protected QueryFilterProvider _QueryFilterProvider;
#endregion #endregion
#region Init mppingInfo #region Init mppingInfo

19
SqlSugar/SqlSugarClient.cs

@ -283,6 +283,25 @@ namespace SqlSugar
} }
#endregion #endregion
#region Gobal Filter
public QueryFilterProvider QueryFilter
{
get
{
if (base._QueryFilterProvider == null)
{
base._QueryFilterProvider = new QueryFilterProvider();
base._QueryFilterProvider.Context = this;
}
return _QueryFilterProvider;
}
set
{
base._QueryFilterProvider = value;
}
}
#endregion
#region Dispose OR Close #region Dispose OR Close
public virtual void Close() public virtual void Close()
{ {

Loading…
Cancel
Save