I am creating a task to retrieve data and I have an error when it gives two parameters to 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()
;
}
CodePudding user response:
You can't use anonymous objects with IQueryable like this unless you use generics
But here's a simpler solution that may help you: First, create a class
public class KeyValuePairs
{
public int Key {get; set;}
public string Value {get; set;}
}
Next, use your method to return what you need:
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()
;
}
I removed the asynchronous since there isn't an awaiter.