本帖最後由 staymen 於 2021-1-6 01:51 編輯
回覆 13# antlee
yes self join
self join Post Table, 如果唔知tree 有幾層. 幾多層Child 就有幾多層咁
找就找到這個:
但就係以上有人講會全部 RECORD, All record of Table Post, 用SQL拎曬出黎, store in memory,再filter? Then ToList(). 建立Object然後多RECORD 就死得.
https://entityframeworkcore.com/ ... e-to-ef-core-entity
public override IEnumerable<Post> GetAll()
{
return Table
.Include(x => x.Children)
.AsEnumerable()
.Where(x => x.Parent == null)
.ToList();
}
所以都係要直接run SQL 比較好? LINQ 處理 self ref parent/child tree structure 就死得? |