[英]EntityFramework Core nullable predicate ToListAsync
我如何使用可空謂詞在 EFCore 中獲取 ToListAsync 擴展。
Func<User, bool>? predicate = x => x.IsActive;
var result = await _context
.User
.Where(predicate)
.ToListAsync(); // This extension is not available in this case
var anotherResult = await _context
.User
.Where(x => x.IsActive)
.ToListAsync(); // Extension is available
我需要謂詞可以為空,因為它將成為該方法的可選參數。 有沒有辦法處理Where
中的可空謂詞?
它要從你那里得到的 Expression 委托在哪里。 如果您提供下面的代碼,它將起作用
Expression<Func<User, bool>> predicate = x => x.IsActive;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.