Skip to content

Commit

Permalink
Update Nav.Dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
DotNetNext committed Sep 29, 2023
1 parent 7a75039 commit 4ba9ecc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Src/Asp.NetCore2/SqlSeverTest/UnitTest/UnitNavDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ public static void Init()
{
var db = NewUnitTest.Db;
var list=db.Queryable<UnitAddress011>().Includes(x => x.Persons).ToList();
var list2 = db.Queryable<UnitPerson011>()
.Includes(x => x.adds)
.Includes(x => x.adds2).ToList();
if (list.First().Persons.Count() != 1)
{
throw new Exception("unit error");
}
if (list2.First().adds==null)
{
throw new Exception("unit error");
}
if (list2.Last().adds2 == null)
{
throw new Exception("unit error");
}
}
[SqlSugar.SugarTable("UnitPerson0x1x1")]
public class UnitPerson011
Expand All @@ -20,6 +35,10 @@ public class UnitPerson011
public string Name { get; set; }
public int AddressId { get; set; }
public int AddressId2 { get; set; }
[SqlSugar.Navigate(SqlSugar.NavigateType.Dynamic, "[{m:\"AddressId\",c:\"Id\"},{m:\"AddressId\",c:\"Id\"}]")]
public UnitAddress011 adds { get; set; }
[SqlSugar.Navigate(SqlSugar.NavigateType.Dynamic, "[{m:\"AddressId2\",c:\"Id\"},{m:\"AddressId2\",c:\"Id\"}]")]
public UnitAddress011 adds2 { get; set; }
}
[SqlSugar.SugarTable("UnitAddress0x1x1")]
public class UnitAddress011
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ private void DynamicOneToOne(List<object> list, Func<ISugarQueryable<object>, Li
var navEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(navEntity);
this.Context.InitMappingInfo(navEntity);
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
if (IsJsonMapping(navObjectNameColumnInfo, sqlObj))
{
CreateDynamicMappingExpression(sqlObj, navObjectNameColumnInfo.Navigat.Name, navEntityInfo, listItemEntity);
}
Check.ExceptionEasy(sqlObj.MappingExpressions.IsNullOrEmpty(), $"{expression} error,dynamic need MappingField ,Demo: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())", $"{expression}解析出错, 自定义映射需要 MappingField ,例子: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())");
if (list.Any() && navObjectNamePropety.GetValue(list.First()) == null)
{
Expand Down

0 comments on commit 4ba9ecc

Please sign in to comment.