- 优化 MapRead 对 NULL 字段的处理;

This commit is contained in:
2881099 2020-11-09 00:57:53 +08:00
parent d01cbdd8df
commit 58be3b77f3
2 changed files with 37 additions and 2 deletions

View File

@ -10,6 +10,41 @@ namespace FreeSql.Tests
{
public class UnitTest4
{
[Fact]
public void LeftJoinNull01()
{
var fsql = g.sqlite;
fsql.Delete<leftjoin_null01>().Where("1=1").ExecuteAffrows();
fsql.Delete<leftjoin_null02>().Where("1=1").ExecuteAffrows();
var item = new leftjoin_null01 { name = "xx01" };
fsql.Insert(item).ExecuteAffrows();
var sel1 = fsql.Select<leftjoin_null01, leftjoin_null02>()
.LeftJoin((a, b) => a.id == b.null01_id)
.First((a, b) => new
{
a.id,
a.name,
id2 = (Guid?)b.id,
time2 = (DateTime?)b.time
});
Assert.Null(sel1.id2);
Assert.Null(sel1.time2);
}
class leftjoin_null01
{
public Guid id { get; set; }
public string name { get; set; }
}
class leftjoin_null02
{
public Guid id { get; set; }
public Guid null01_id { get; set; }
public DateTime time { get; set; }
}
[Fact]
public void TestHzyTuple()

View File

@ -178,14 +178,14 @@ namespace FreeSql.Internal
parent.Property = parentProp; //若不加此行,会引用 GroupBy(..).ToList(a => new Dto { key = a.Key }) null 错误CopyTo 之后 Property 变为 null
return false;
}
parent.CsType = exp.Type;
if (parent.CsType == null) parent.CsType = exp.Type;
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
field.Append(", ").Append(parent.DbField);
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false &&
parent.DbField.EndsWith(_common.QuoteSqlName(parent.CsName), StringComparison.CurrentCultureIgnoreCase) == false //DbField 和 CsName 相同的时候,不处理
) field.Append(_common.FieldAsAlias(parent.CsName));
parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
if (parent.MapType == null) parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
return false;
}
return false;