none
Implementing IQueryProvider and IQueryable RRS feed

  • Question

  • Hi, I'm working on a project and I'd like to implement Linq queries on my data, so that it makes the development easier and more streamlined.

    However I'm having trouble figuring out / finding decent material on the net on how to implement the functionality.

    Could somebody please possibly finish the code below to represent a complete Linq implementation:

    public class Student
    {
       string fName;
       string lName;
       DateTime doB;
    }

    public class Register
    {
       private List<Student> ... etc
    }

    Can you please complete it so that a query such as the one below could be performed.

    var q = from s in registerInstance where s.lName.StartsWith('p') && s.doB.Year == 1990;

    A VisualBasic Novice, In Need Of Help...
    Tuesday, March 31, 2009 4:51 AM

Answers

  • Writing an entire query provider is beyond the scope this forum which is just for support on the LINQ to SQL provider.

    Matt Warren has a series of blog posts about writing your own at http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx but I wouldn't underestimate the complexity of the task.

    If you just want an in-memory collection then you can expose as IEnumerable<T> and just let LINQ to Objects loop over all your entries to see if they match although this obviously won't be as fast as something that uses indexes etc.

    public class Register
    {
     private IEnumerable<Student> Students = new List<Student>();
    }

    [)amien

    @Matt: You're right, updated!
    Tuesday, March 31, 2009 3:57 PM
    Moderator

All replies

  • Writing an entire query provider is beyond the scope this forum which is just for support on the LINQ to SQL provider.

    Matt Warren has a series of blog posts about writing your own at http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx but I wouldn't underestimate the complexity of the task.

    If you just want an in-memory collection then you can expose as IEnumerable<T> and just let LINQ to Objects loop over all your entries to see if they match although this obviously won't be as fast as something that uses indexes etc.

    public class Register
    {
     private IEnumerable<Student> Students = new List<Student>();
    }

    [)amien

    @Matt: You're right, updated!
    Tuesday, March 31, 2009 3:57 PM
    Moderator
  • Damien, I think you meant IEnumerable not IQueryable.
    Wayward LINQ Lacky
    Wednesday, April 1, 2009 2:26 AM
    Moderator