我的私人獲取所有方法
private IQueryable<Category> getAll()
=> _unitOfWork.CategoryRepo
.GetAll()
.Include(x => x.CategoryDetails)
.Include(x => x.Categories)
.ThenInclude(x => x.CategoryDetails);
這是我嘗試過的:
await getAll().OrderBy(x => x.Id).TakeLast(1000).ToListAsync()
錯誤(.net 6 和 3.1 中的相同錯誤):
The LINQ expression 'DbSet<Category>()
.Include(x => x.CategoryDetails)
.Include(x => x.Categories)
.ThenInclude(x => x.CategoryDetails)
.OrderBy(x => x.Id)
.TakeLast(__p_0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
uj5u.com熱心網友回復:
好吧TakeLast不能翻譯成SQL,但你為什么要使用TakeLast呢?
await getAll().OrderByDescending(x => x.Id).Take(1000).ToListAsync()
所以以所需的方式訂購,然后使用Take而不是TakeLast.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/427131.html
上一篇:如何使用URI通過Intent在另一個應用程式中打開檔案?
下一篇:如何從Sql查詢撰寫Linq查詢
