32

Is there a plan to make Dapper.net compatible with IQueryable interfaces? If not, what's the workaround to use Dapper with "Expression Trees" filters?

JK.
  • 20,752
  • 32
  • 128
  • 207
Bill
  • 1,469
  • 8
  • 51
  • 98

3 Answers3

56

No, there are no plans to do this. It is far far outside what dapper tries to do. So far that I would say it is antithetical. Dapper core tries to be the friend to those who love their SQL.

Marc Gravell
  • 976,458
  • 251
  • 2,474
  • 2,830
  • Great answer - If any doesnt like SQL, there are other solutions like Entity Framework. – Nils Anders Dec 30 '14 at 08:33
  • 5
    I really like SQL (or I really like to like SQL). but i also like getting paid early. Screw SQL, i want to deploy. Entity Framework for SQLite it is! – jokab Aug 25 '16 at 04:47
  • 6
    I'm sorry SQL, I really meant screw OData! Forgive me, I'm crawling back to your arms! – jokab Aug 25 '16 at 04:56
1

You can get IQueryable from IEnumerable using the built-in extension method AsQueryable in System.Linq namespace

public IQueryable<Order> GetOrdersAsQuerable()
{
    IEnumerable<Order> qry= GetOrders(); //using Query<T>
    //use the built-in extension method  AsQueryable in  System.Linq namespace
    return qry.AsQueryable();            
}

Example

M.Hassan
  • 9,296
  • 5
  • 57
  • 79
  • 17
    But it won't be a real IQueryable object and so it doesn't have any benefits. – kipusoep Jan 09 '18 at 17:23
  • 2
    yes, but you can use the IQueryable version to bind, for example GridView in Asp.net and benefit for sorting (you can't sort using IEnumerable version). – M.Hassan Jan 09 '18 at 22:01
  • 2
    Sure, it's pretending to be an IQueryable object, but we all know it isn't and AFAIK the benefits of a real IQueryable do not apply if you mock it, right? – kipusoep Jan 10 '18 at 06:22
  • 1
    The value of `IQueryable ` in e.g. EF or linq2Sql is lazy executing to the last minute and generate sql that sent to the server. but, the story is different in Dapper. In Dapper you do all filters in a parametric sql statement using `Query` and get `IEnumerable`. You gain extra benefit by using `AsQuerable` and get dynamic sorting that you have to implement it without `AsQuerable`. see: https://stackoverflow.com/questions/1106802/why-use-asqueryable-instead-of-list#comment8817475_4096467 – M.Hassan Jan 11 '18 at 00:26
  • This is not the expected behavior JK. seems to want. This is just a cast, JK. seembs to want a EF behavior creating the Query dynamically. – gatsby Sep 03 '18 at 07:13
0

Checkout Dapper.TQuery NuGet package for that.