- 增加 [Navigate(xx, TempPrimary = xx)] 与非主键关联;(仅支持查询)

This commit is contained in:
2881099
2023-03-02 15:46:45 +08:00
parent c6556a47ab
commit da7bb7c74d
14 changed files with 243 additions and 101 deletions

View File

@ -38,7 +38,7 @@ namespace FreeSql.Internal.Model
{
_refs.AddOrUpdate(propertyName, tbref, (ok, ov) => tbref);
}
public TableRef GetTableRef(string propertyName, bool isThrowException)
public TableRef GetTableRef(string propertyName, bool isThrowException, bool isCascadeQuery = true)
{
if (_refs.TryGetValue(propertyName, out var tryref) == false) return null;
if (tryref.Exception != null)
@ -46,6 +46,18 @@ namespace FreeSql.Internal.Model
if (isThrowException) throw tryref.Exception;
return null;
}
if (isCascadeQuery == false && tryref.IsTempPrimary == true)
{
if (isThrowException)
{
switch (tryref.RefType)
{
case TableRefType.OneToMany: throw new Exception($"[Navigate(\"{string.Join(",", tryref.RefColumns.Select(a => a.CsName))}\", TempPrimary = \"{string.Join(",", tryref.Columns.Select(a => a.CsName))}\")] Only cascade query are supported");
case TableRefType.ManyToOne: throw new Exception($"[Navigate(\"{string.Join(",", tryref.Columns.Select(a => a.CsName))}\", TempPrimary = \"{string.Join(",", tryref.RefColumns.Select(a => a.CsName))}\")] Only cascade query are supported");
}
}
return null;
}
return tryref;
}
public IEnumerable<KeyValuePair<string, TableRef>> GetAllTableRef() => _refs;
@ -160,6 +172,7 @@ namespace FreeSql.Internal.Model
public List<ColumnInfo> RefColumns { get; set; } = new List<ColumnInfo>();
public Exception Exception { get; set; }
public bool IsTempPrimary { get; set; }
}
public enum TableRefType
{