In this article we will learn, how to AsQueryable() method in LINQ or what is AsQueryable() method in LINQ C# MVC with example.


In LINQ, AsQueryable() method is used to cast or convert specific type of given list items to As IQueryable<T>

Example of LINQ AsQueryable() Method


Following is the example of using LINQ AsQueryable method to convert input list items to IQueryable.


using System;
using System.Collections.Generic;
using System.Linq;
namespace SQLTutorialsPoint
    class Employee
        public string Name { get; set; }
        public int ID { get; set; }
    class Program
        static void Main(string[] args)
            List<Employee> Employee = new List<Employee>(){
            new Employee() {  Name = "Suresh",ID  = 1},
            new Employee() {  Name = "Sekher", ID=  2 },
              new Employee() {  Name = "Sumit", ID=  3 },
            new Employee() {  Name = "Pankaj", ID = 4},
            new Employee() {  Name = "Rahul", ID = 5}};
            IQueryable<Employee> result = Employee.AsQueryable().Where(x =>x.Name.Contains("Suresh"));
            foreach (var item in result)
                Console.WriteLine(" ID:" + item.ID +"Name:"+item.Name);               

As you see above example we are converting “Employee” list / collection items to IQueryable to filter data using AsQueryable method.


Now we will run and see the output.

Use LINQ AsQueryable Method


In this article we learned, how we can use LINQ AsQueryable method to convert input sequence elements to IQueryable list to get required elements by filtering list in c#.


I hope it will help to you after reading.


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like