- 优化 IsNullable = false 插入的数据值为 null 则以默认值插入(防止DB报错);#384

This commit is contained in:
28810 2020-08-03 11:58:46 +08:00
parent 2f254d23f9
commit 0b1865f7e7
7 changed files with 19 additions and 21 deletions

View File

@ -125,13 +125,6 @@
清空状态数据 清空状态数据
</summary> </summary>
</member> </member>
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
根据 lambda 条件删除数据
</summary>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:FreeSql.DbSet`1.Add(`0)"> <member name="M:FreeSql.DbSet`1.Add(`0)">
<summary> <summary>
添加 添加
@ -520,14 +513,5 @@
<param name="that"></param> <param name="that"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
<summary>
批量注入 Repository可以参考代码自行调整
</summary>
<param name="services"></param>
<param name="globalDataFilter"></param>
<param name="assemblies"></param>
<returns></returns>
</member>
</members> </members>
</doc> </doc>

View File

@ -156,9 +156,23 @@ namespace FreeSql.Tests
} }
} }
class testInsertNullable
{
[Column(IsIdentity = true)]
public long Id { get; set; }
[Column(IsNullable = false)]
public string str1 { get; set; }
[Column(IsNullable = false)]
public int? int1 { get; set; }
}
[Fact] [Fact]
public void Test03() public void Test03()
{ {
g.sqlite.Insert(new testInsertNullable()).NoneParameter().ExecuteAffrows();
var sqlxx = g.pgsql.InsertOrUpdate<userinfo>().SetSource(new userinfo { userid = 10 }).UpdateColumns(a => new { a.birthday, a.CardNo }).ToSql(); var sqlxx = g.pgsql.InsertOrUpdate<userinfo>().SetSource(new userinfo { userid = 10 }).UpdateColumns(a => new { a.birthday, a.CardNo }).ToSql();
var aff1 = g.sqlite.GetRepository<Edi, long>().Delete(10086); var aff1 = g.sqlite.GetRepository<Edi, long>().Delete(10086);

View File

@ -548,7 +548,7 @@ namespace FreeSql.Internal.CommonProvider
else else
{ {
object val = col.GetMapValue(d); object val = col.GetMapValue(d);
if (val == null && col.Attribute.IsNullable == false) val = Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384 if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
if (_noneParameter) if (_noneParameter)
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
else else

View File

@ -67,7 +67,7 @@ namespace FreeSql.Dameng.Curd
else else
{ {
object val = col.GetMapValue(d); object val = col.GetMapValue(d);
if (val == null && col.Attribute.IsNullable == false) val = Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384 if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
if (_noneParameter) if (_noneParameter)
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
else else

View File

@ -67,7 +67,7 @@ namespace FreeSql.Odbc.Dameng
else else
{ {
object val = col.GetMapValue(d); object val = col.GetMapValue(d);
if (val == null && col.Attribute.IsNullable == false) val = Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384 if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
if (_noneParameter) if (_noneParameter)
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
else else

View File

@ -67,7 +67,7 @@ namespace FreeSql.Odbc.Oracle
else else
{ {
object val = col.GetMapValue(d); object val = col.GetMapValue(d);
if (val == null && col.Attribute.IsNullable == false) val = Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384 if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
if (_noneParameter) if (_noneParameter)
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
else else

View File

@ -69,7 +69,7 @@ namespace FreeSql.Oracle.Curd
else else
{ {
object val = col.GetMapValue(d); object val = col.GetMapValue(d);
if (val == null && col.Attribute.IsNullable == false) val = Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384 if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
if (_noneParameter) if (_noneParameter)
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
else else