Custom LINQ provider (Continued..)

In my last post , I showed the basics of creating a custom LINQ provider, now moving forward , we just wont query against Name property only, we also may need to query against ID or Age of the Person object.


Therefore, we must fuse a method that will enable to use the query against any property. In simple, we can create a common BinaryExpression processor, that will build up the query object using reflection, which will be used to fetch similar item from the repository. This is, though a fictions Person class and nothing to do with Provider basics, the change is  useful for creating any real life project.I sightly modified the PersonContext class from previous post to support query against all properties.

Now, ProcessExpression method will call only ProcessBinaryResult, for any type of Binary expression processing.


ProcessBinaryResult in turn will call ProcessItem, which will take the query (Person) object and will match against its list.For ex, for Equal expression, ProcessItem will have the following code.


PersonContext class with recent changes can be downloaded here. After updating the project(which is attached previously) with the new class, it is possible to use queries like p.Age == 40 , or p.ID = 1,  or query against any new properties that has been added to Person class.

In Short, the power of LINQ query is to query against any object , it could be SQL, XML, or custom, and being able to query any property, does make a provider more useful.

Let me know , if it is useful.

kick it on

No Comments