I saw the great performance of Dapper and some samples of how to use it.
I was wondering if I can use it to provide IQueryable data and integrate it with UI layer using ODATA to transfer data to the UI (like grids, lists,...).
Is there any way to return Dapper objects AsQueryable instead of IEnumerable to query using ODATA?
To use Dapper with OData, you would have to intercept the
Get(ODataQueryOptions<SpotView> queryOptions)
parameter, parse it, and create your Dapper's where clause out of it. You would also need to take into consideration any other OData settings you have in your WebApiConfig.cs in theBut, you can also use MySqlConnection with EF and you don't have to re-invent the wheel with the above parsing. But, then it's your decision if Dapper's performance is more important than using a full ORM like EF which already has differed execution built into it.
I recently found myself in this situation where I wanted to use Dapper with OData but I did not want to use Entity Framework for SQLite.
My solution was to create a extension method for ODataQueryOptions so my controllers would look like this
This looks straightforward and it works for me so far so I'm sticking with it. I just had to limit what users can filter as far as odata is concerned
And here is the extension method
No, not really. Well, you can wrap any sequence with .AsQueryable() if you really want, but it will just be using LINQ-to-Objects. Dapper is deliberately simple; it tries to do very little, but what it does try to do: it does damned well (even if I do say so myself). A proper IQueryable interface is the exact opposite of dapper...