I have a list of objects List<Student>
that I want return as an IQueryable<Student>
.
When I try to use .AsQueryable()
on the list to convert it to IQueryable<Student>
I got a System.Collections.Generic.List`1[ConsoleApp.Student]
.
How I can convert list to IQueryable()
?
See below I minimum reproducible example:
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp
{
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
}
internal class Program
{
static void Main(string[] args)
{
var students = new List<Student>() ;
students.Add(new Student() { Id = 1, Name = "J" });
students.Add(new Student() { Id = 2, Name = "X" });
IQueryable<Student> queryable = students.AsQueryable();
Console.WriteLine("Hello, World!");
}
}
}