You must Sign In to post a response.
  • Category: LINQ

    How to make a object queriable using linq

    What interfaces a .net object should implement to be queriable using linq?
  • #746144
    The Interface name is IQueryable. You need to implement this in order to make an object as IQuerable.
    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #746158

    IQueryable need to implement as Anil Kumar said,

    some addition points for you

    1.System.Linq Namespace is use for IQueryable
    2.we can use for LINQ and SQl Queries

    public List<Custom> MYLINQ()
    List<Custom> lit = new List<Custom>();
    MyData objData = new MyData();
    IQueryable<Custom> listQuery = objData.Customers.Where(e => e.department.StartsWith("R"));
    listQuery = listQuery.Take<Custom>(5);
    lit = listQuery.ToList();
    catch(Exception ex)

    return lit;

    you can use this code

  • #746167
    Hai Praveen,
    yes, the System.Linq namespace uses the IQueryable interface to query in the collection objects.

    DataContext dcIQueryable = new DataContext();
    var x = dcIQueryable.Employees.Where(a => a.FirstName.StartsWith("p"));

    You can also go through the below link for more details:

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • Sign In to post your comments