- 增加 .Net Framework 4.0 的支持,出于环境考虑 .Net Framework 4.0 不支持异步方法;

- 增加 IFreeSql.Insert<T>(IEnumerable<T1> source) 方法;
This commit is contained in:
28810
2019-10-21 15:14:18 +08:00
parent cb3e3b02ef
commit de8cf9e17d
139 changed files with 2798 additions and 1868 deletions

View File

@ -19,9 +19,13 @@ namespace FreeSql.Sqlite.Curd
{
throw new NotImplementedException();
}
#if net40
#else
public override Task<List<T1>> ExecuteDeletedAsync()
{
throw new NotImplementedException();
}
#endif
}
}

View File

@ -17,12 +17,8 @@ namespace FreeSql.Sqlite.Curd
}
public override int ExecuteAffrows() => base.SplitExecuteAffrows(5000, 999);
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(5000, 999);
public override long ExecuteIdentity() => base.SplitExecuteIdentity(5000, 999);
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(5000, 999);
public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(5000, 999);
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(5000, 999);
protected override long RawExecuteIdentity()
{
@ -50,6 +46,22 @@ namespace FreeSql.Sqlite.Curd
}
return ret;
}
protected override List<T1> RawExecuteInserted()
{
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return new List<T1>();
this.RawExecuteAffrows();
return _source;
}
#if net40
#else
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(5000, 999);
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(5000, 999);
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(5000, 999);
async protected override Task<long> RawExecuteIdentityAsync()
{
var sql = this.ToSql();
@ -76,14 +88,6 @@ namespace FreeSql.Sqlite.Curd
}
return ret;
}
protected override List<T1> RawExecuteInserted()
{
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return new List<T1>();
this.RawExecuteAffrows();
return _source;
}
async protected override Task<List<T1>> RawExecuteInsertedAsync()
{
var sql = this.ToSql();
@ -92,5 +96,6 @@ namespace FreeSql.Sqlite.Curd
await this.RawExecuteAffrowsAsync();
return _source;
}
#endif
}
}

View File

@ -19,19 +19,13 @@ namespace FreeSql.Sqlite.Curd
}
public override int ExecuteAffrows() => base.SplitExecuteAffrows(200, 999);
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(200, 999);
public override List<T1> ExecuteUpdated() => base.SplitExecuteUpdated(200, 999);
public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(200, 999);
protected override List<T1> RawExecuteUpdated()
{
throw new NotImplementedException();
}
protected override Task<List<T1>> RawExecuteUpdatedAsync()
{
throw new NotImplementedException();
}
protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys)
{
@ -68,5 +62,16 @@ namespace FreeSql.Sqlite.Curd
}
sb.Append(")");
}
#if net40
#else
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(200, 999);
public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(200, 999);
protected override Task<List<T1>> RawExecuteUpdatedAsync()
{
throw new NotImplementedException();
}
#endif
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
<Version>0.10.14</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
@ -30,4 +30,8 @@
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
<DefineConstants>net40</DefineConstants>
</PropertyGroup>
</Project>

View File

@ -150,6 +150,8 @@ namespace FreeSql.Sqlite
}
}
#if net40
#else
async public Task OnGetAsync(Object<DbConnection> obj)
{
@ -177,6 +179,7 @@ namespace FreeSql.Sqlite
}
}
}
#endif
public void OnGetTimeout()
{
@ -222,21 +225,6 @@ namespace FreeSql.Sqlite
return false;
}
}
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
{
try
{
await PingCommand(that).ExecuteNonQueryAsync();
return true;
}
catch
{
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
if (isThrow) throw;
return false;
}
}
public static void OpenAndAttach(this DbConnection that, string[] attach)
{
that.Open();
@ -252,6 +240,23 @@ namespace FreeSql.Sqlite
cmd.ExecuteNonQuery();
}
}
#if net40
#else
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
{
try
{
await PingCommand(that).ExecuteNonQueryAsync();
return true;
}
catch
{
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
if (isThrow) throw;
return false;
}
}
async public static Task OpenAndAttachAsync(this DbConnection that, string[] attach)
{
await that.OpenAsync();
@ -267,5 +272,6 @@ namespace FreeSql.Sqlite
await cmd.ExecuteNonQueryAsync();
}
}
#endif
}
}

View File

@ -50,7 +50,11 @@ namespace FreeSql.Sqlite
if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new (int, string, string, bool?, object)?(((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue));
if (type.IsArray) return null;
var enumType = type.IsEnum ? type : null;
if (enumType == null && type.IsNullableType() && type.GenericTypeArguments.Length == 1 && type.GenericTypeArguments.First().IsEnum) enumType = type.GenericTypeArguments.First();
if (enumType == null && type.IsNullableType())
{
var genericTypes = type.GetGenericArguments();
if (genericTypes.Length == 1 && genericTypes.First().IsEnum) enumType = genericTypes.First();
}
if (enumType != null)
{
var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?

View File

@ -381,7 +381,7 @@ namespace FreeSql.Sqlite
case "AddTicks": return $"datetime({left},(({args1})/10000000)||' seconds')";
case "AddYears": return $"datetime({left},({args1})||' years')";
case "Subtract":
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault() : exp.Arguments[0].Type).FullName)
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName)
{
case "System.DateTime": return $"(strftime('%s',{left})-strftime('%s',{args1}))";
case "System.TimeSpan": return $"datetime({left},(({args1})*-1)||' seconds')";

View File

@ -17,6 +17,7 @@ namespace FreeSql.Sqlite
public IInsert<T1> Insert<T1>(T1 source) where T1 : class => this.Insert<T1>().AppendData(source);
public IInsert<T1> Insert<T1>(T1[] source) where T1 : class => this.Insert<T1>().AppendData(source);
public IInsert<T1> Insert<T1>(List<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
public IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
public IUpdate<T1> Update<T1>() where T1 : class => new SqliteUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
public IUpdate<T1> Update<T1>(object dywhere) where T1 : class => new SqliteUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
public IDelete<T1> Delete<T1>() where T1 : class => new SqliteDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);