WHERE IN parameter

Jul 12, 2011 at 2:23 PM

Great work so far on DbExecutor i realy like it!

One feature that i'm missing at the moment is WHERE IN.

example:

var orderNrs = new[] { 355387, 355439 };
var products2 = DbExecutor.ExecuteReaderDynamic(_connectionFactory(), 
  @" SELECT * FROM Orders WHERE OrderNr IN {0}" , 
  new { OrderNr = orderNrs })
  .Select(d => new { d.Id, d.OrderNr })
  .ToArray();

Could that be implemented in DbExecutor?

Coordinator
Jul 13, 2011 at 2:51 AM

Thank you for use.
Here is example.

// SQL Server and NORTHWIND Db Sample
var customers = DbExecutor.ExecuteReaderDynamic(connectionFactory(),
        @"select * from Customers
          where Country in (@Country1, @Country2)",
        new { Country1 = "UK", Country2 = "Mexico" })
    .Select(d => new { d.CustomerID, d.Country })
    .ToArray();

I hope you will find it helpful.

Jul 13, 2011 at 6:25 AM

If you have a fixed number of parameters you can do that.

In my example i can have 10 to 100 OrderNrs, it would be nice if you could use an array of items as parameter.

Coordinator
Jul 13, 2011 at 7:56 AM

Sorry, I misread it.
I understood a meaning of the suggestion.

// like this API
var customers = DbExecutor.ExecuteReaderDynamic(connectionFactory(),
        @"select * from Customers
          where Country in @Countries",
        new { Countries = new[]{"UK", "Mexico" }})
    .Select(d => new { d.CustomerID, d.Country })
    .ToArray();
It seems to be surely useful.
I'll make this feature at the time of the next update.

Thank you for a splendid request!