Search code examples
c#servicestackormlite-servicestack

What is SqlExpressionVisitor


I am new to ServiceStack & OrmLite, during my work, I frequently come across SqlExpressionVisitor

And my question is:

What is it basically? and what are the benefits of using it? And can I get the raw string query out of it?


Solution

  • You have an enumeration, on which you can do, Linq queries: Where, OrderBy, Skip, Take. this goes through the enumeration and returns you a resulting enumerable.

    With ORM Lite (and Entity Framework) you can also do this. But instead of using an IEnumerable, they use an IQueryable. This interface gives you the same usages as these LINQ queries, but behind the scene these are not compiled to DLL code. Instead they are kept as Expressions.

    The SqlExpressionVisitor reads this expression and tries to turn it into a SQL Query, which can be executed and returning a IEnumerable<T> of this IQueryable<T>, which is a list of results from the query.

    You can also this way build your own IQueryable LINQ provider: https://msdn.microsoft.com/en-us/library/bb546158.aspx (for a third party API or other databases).