[英]Query cannot be translated EF Core
我使用 asp.net 樣板文件並嘗試通過布爾標志和權限過濾用戶。
這是方法的代碼
private async Task<List<User>> GetAdminUsers()
{
using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
var adminUsers = await _userManager.Users.Where(x => x.IsFuelAdmin && _permissionChecker
.IsGranted(new UserIdentifier(null, x.Id),
FuelAdministratorPermissions.Pages_Administration_Missing_PreQual_LoanAmount_Email_Notifications))
.ToListAsync();
return adminUsers;
}
}
但它失敗了這個錯誤
ionHandling.AbpExceptionFilter: LINQ 表達式 'DbSet.Where(u => __ef_filter__p_0 ||.(((ISoftDelete)u).IsDeleted) && __ef_filter__p_1 || ((IMayHaveTenant)u).TenantId == __ef_filter__CurrentTen > u.IsFuelAdmin).Where(u => ___permissionChecker_0:IsGranted(user, new UserIdentifier(null.u,Id): permissionName. "Pages.Administration.QualificationChecks.LoanAmount_Email_Notifications"))' 無法翻譯,要么重寫查詢以可以翻譯的形式,或通過插入對 AsEnumerable()、AsAsyncEnumerable()、ToList() 或 ToListAsync() 的調用顯式切換到客戶端評估
我該如何解決這個問題?
數據庫服務器上沒有“IsGranted”function。 您不能將 IsGranted 用作 db function。
如果要使用本地 C# IsGranted
,請將 adminUsers 放入 C# 本地列表並過濾,然后為 IsGranted:
var adminUsers = await _userManager.Users.Where(x => x.IsFuelAdmin).ToListAsync();
對於完整的 SQL 查詢,您必須與您的用戶建立一個連接查詢:
userRoleRepository、userPermissionRepository、rolePermissionRepository
查看接受答案: 獲取具有特定權限的所有用戶?
您可以定義其他屬性 - 例如 IsAdmin - 並在該查詢之前的運行時中設置它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.