mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 优化 IsNullable = false 插入的数据值为 null 则以默认值插入(防止DB报错);#384
This commit is contained in:
		@@ -125,13 +125,6 @@
 | 
			
		||||
            清空状态数据
 | 
			
		||||
            </summary>
 | 
			
		||||
        </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)">
 | 
			
		||||
            <summary>
 | 
			
		||||
            添加
 | 
			
		||||
@@ -520,14 +513,5 @@
 | 
			
		||||
            <param name="that"></param>
 | 
			
		||||
            <returns></returns>
 | 
			
		||||
        </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>
 | 
			
		||||
</doc>
 | 
			
		||||
 
 | 
			
		||||
@@ -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]
 | 
			
		||||
        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 aff1 = g.sqlite.GetRepository<Edi, long>().Delete(10086);
 | 
			
		||||
 
 | 
			
		||||
@@ -548,7 +548,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        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)
 | 
			
		||||
                            sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
 | 
			
		||||
                        else
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,7 @@ namespace FreeSql.Dameng.Curd
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        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)
 | 
			
		||||
                            sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
 | 
			
		||||
                        else
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,7 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        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)
 | 
			
		||||
                            sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
 | 
			
		||||
                        else
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,7 @@ namespace FreeSql.Odbc.Oracle
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        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)
 | 
			
		||||
                            sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
 | 
			
		||||
                        else
 | 
			
		||||
 
 | 
			
		||||
@@ -69,7 +69,7 @@ namespace FreeSql.Oracle.Curd
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        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)
 | 
			
		||||
                            sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
 | 
			
		||||
                        else
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user