1

When using the SqlBuilder class of DBExtensions, is it possible to build multiple select statements that are executed in a single round trip?

Something along the lines of:

select t1.* from Table1 t1 where t1.Foo = 'Bar 1';
select t2.* from Table2 t2 where t2.Foo = 'Bar 2';
DanP
  • 6,310
  • 4
  • 40
  • 68

1 Answers1

3

For the building part, you can do:

var query1 = SQL
   .SELECT("t1.*")
   .FROM("Table1 t1")
   .WHERE("t1.Foo = {0}", "Bar 1");

var query2 = SQL
   .SELECT("t2.*")
   .FROM("Table2 t2")
   .WHERE("t2.Foo = {0}", "Bar 2");

var batchQuery = SqlBuilder.JoinSql(";", query1, query2);

About execution, I have no idea if your ADO.NET provider supports batch SELECT queries, maybe you want to do a UNION query instead?

Max Toro
  • 28,282
  • 11
  • 76
  • 114
  • Thank you - exactly what I was looking for! And yes, my provider (SQL Server) allows for multiple chained queries like this. – DanP Jan 27 '14 at 17:44