Browse Source

Upgrading the Navigation Configuration

SqlSugar5
sunkaixuan 2 years ago
parent
commit
506861145e
  1. 1
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs
  2. 11
      Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs
  3. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs
  4. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs

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

@ -327,6 +327,7 @@ namespace SqlSugar
{
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
var navList = selector(this.Context.Queryable<object>().AS(navEntityInfo.DbTableName)
.WhereIF(navObjectNameColumnInfo.Navigat.WhereSql.HasValue(), navObjectNameColumnInfo.Navigat.WhereSql)
.WhereIF(sqlObj.WhereString.HasValue(),sqlObj.WhereString)
.AddParameters(sqlObj.Parameters).Where(conditionalModels));
var groupQuery = (from l in list

11
Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs

@ -228,6 +228,7 @@ namespace SqlSugar
public string MappingAId { get; set; }
public string MappingBId { get; set; }
public NavigateType NavigatType { get; set; }
public string WhereSql { get; set; }
public Navigate(NavigateType navigatType,string name)
{
this.Name = name;
@ -239,6 +240,16 @@ namespace SqlSugar
this.Name2 = lastName;
this.NavigatType = navigatType;
}
public Navigate(NavigateType navigatType, string firstName, string lastName,string whereSql)
{
this.Name = firstName;
this.Name2 = lastName;
this.NavigatType = navigatType;
this.WhereSql = whereSql;
Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一");
}
public Navigate(Type MappingTableType,string typeAiD,string typeBId)
{
this.MappingType = MappingTableType;

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

@ -98,6 +98,7 @@ namespace SqlSugar
selectName = queryable.QueryBuilder.Builder.GetTranslationColumnName(selectName);
mapper.Sql = queryable
.AS(this.ProPertyEntity.DbTableName)
.WhereIF(Navigat.WhereSql.HasValue(),Navigat.WhereSql)
.Where($" {ShorName}.{name}={pk} ").Select(selectName).ToSql().Key;
mapper.Sql = $" ({mapper.Sql}) ";
return mapper;

4
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs

@ -66,6 +66,10 @@ namespace SqlSugar
var navColum = item.ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.Nav.Name);
Check.ExceptionEasy(pkColumn == null, $"{item.ThisEntityInfo.EntityName} need PrimayKey", $"使用导航属性{item.ThisEntityInfo.EntityName} 缺少主键");
var on = $" {ToShortName(shortName)}.{queryable.SqlBuilder.GetTranslationColumnName(pkColumn.DbColumnName)}={ToShortName(formInfo.ThisEntityInfo.DbTableName + (i - 1))}.{queryable.SqlBuilder.GetTranslationColumnName(navColum.DbColumnName)}";
if (item.Nav.WhereSql.HasValue())
{
on = (on + " AND " + item.Nav.WhereSql);
}
queryable.AddJoinInfo(item.ThisEntityInfo.DbTableName,ToShortName(shortName), on, JoinType.Inner);
++i;
lastShortName = shortName;

Loading…
Cancel
Save