Browse Source

Update navigate query

pull/19/head
sunkaixuan 2 years ago
parent
commit
68e290a498
  1. 4
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs
  2. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs
  3. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs

4
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs

@ -295,7 +295,7 @@ namespace SqlSugar
this.Context.InitMappingInfo(navEntityInfo.Type);
var navPkColumn = navEntityInfo.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
Check.ExceptionEasy(navPkColumn==null&& navObjectNameColumnInfo.Navigat.Name2==null, navEntityInfo.EntityName+ "need primarykey", navEntityInfo.EntityName + " 需要主键");
if (navPkColumn==null)
if (navObjectNameColumnInfo.Navigat.Name2.HasValue())
{
navPkColumn = navEntityInfo.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault();
}
@ -341,7 +341,7 @@ namespace SqlSugar
//var navType = navObjectNamePropety.PropertyType;
var listItemPkColumn = listItemEntity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
Check.ExceptionEasy(listItemPkColumn == null&& navObjectNameColumnInfo.Navigat.Name2==null, listItemEntity.EntityName + " not primary key", listItemEntity.EntityName + "没有主键");
if (listItemPkColumn == null)
if (navObjectNameColumnInfo.Navigat.Name2.HasValue())
{
listItemPkColumn = listItemEntity.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault();
}

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs

@ -168,7 +168,7 @@ namespace SqlSugar
private MapperSql GetOneToManySql()
{
var pkColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
if (pkColumn == null && Navigat.Name2 != null)
if (Navigat.Name2.HasValue())
{
pkColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName== Navigat.Name2);
}

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs

@ -78,7 +78,7 @@ namespace SqlSugar
" NavigateType.Dynamic 自定义导航对象不支持在Where(x=>x.自定义.Id==1)等方法中使用"+ this.ProPertyEntity.Type.Name);
}
var pk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
if (pk == null && Navigat.Name2 != null)
if (Navigat.Name2.HasValue())
{
pk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.PropertyName == Navigat.Name2)?.DbColumnName;
}

Loading…
Cancel
Save