我正在創建一個檢索資料的任務,當它向 IQueryable 提供兩個引數時出現錯誤
public async Task<IQueryable<int, string>> ReasonForTheTecruitmentOrder(string type)
{
return _context.Dictionaries
.Where(f => f.Type == type)
.Select( f => new { f.Description, f.Id})
.Distinct()
;
}

uj5u.com熱心網友回復:
除非您使用泛型,否則您不能像這樣使用帶有 IQueryable 的匿名物件
但這里有一個更簡單的解決方案可能會對您有所幫助:首先,創建一個類
public class KeyValuePairs
{
public int Key {get; set;}
public string Value {get; set;}
}
接下來,使用您的方法回傳您需要的內容:
public IQueryable<KeyValuePairs> ReasonForTheTecruitmentOrder(string type)
{
return _context.Dictionaries
.Where(f => f.Type == type)
.Select( f => new KeyValuePairs { Value = f.Description, Key = f.Id})
.Distinct()
;
}
我洗掉了異步,因為沒有等待者。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/440806.html
