tags:

views:

316

answers:

3

Hi

I have a table has 2 columns

Val1 int

Val2 int

My query very simple.

I want to get collection of record have condition (val1=Val2) ,

equivalent to (Select * from table where Val1=Val2)

I try

IDataReader rdr = new Query("Table").WHERE("Val1=Val2").ExecuteReader(); tableColl.LoadAndCloseReader(rdr); rdr.Close();

and

  ..WHERE (" 'Val1=Val2' ")
  ..WHERE (Table.Columns.Val1,IsEqualTo,Table.Columns.Val2) //This not reguler I know
  ..WHERE ("Val"+'='+"Val2") 
  .....

any help be more apricated.

Thanks.

+1  A: 

Unfortunately you'll need to do this as an inline query as far as I know:

TableCollection tableCollection = new InlineQuery()  
  .ExecuteAsCollection<TableCollection>(
    "SELECT * FROM " + Table.Schema.TableName " WHERE " + Table.Columns.Val1 + " = " + Table.Columns.Val2);
Adam
Thanks for your quick answer.Sorry for missing information. I am using Versiyon 2.0.3.I Think DB.Select()... not supported in 2.0.3 versiyon.
No problem, I realised it wouldn't work the way I first suggested anyway. The InlineQuery should exist in 2.0.3 and work
Adam
Thanks for your answers.Unfortunately InlineQuery() not suported In 2.0.3..It seems I must go to upgrade 2.1 version.
I'd recommend skipping 2.1 and compiling the source for 2.2 instead there's a a bunch of bugfixes in it.http://blog.wekeroad.com/subsonic/subsonic-22-released/
Adam
In fact you can get the binaries here http://code.google.com/p/subsonicproject/downloads/list
Adam
A: 

was in same situation recently and came up with this:

TableCollection tablecollection = new TableCollection;
Comparison comp = Comparison.Equals;
tablecollection.Where(Table.Columns.Val1, comp, Table.Columns.Val2);
tablecollection.Load();

i found this better because i don't like inline queries. and it gives more flexibility if you wish to allow for adhoc querying in you app.

jake
i'm using ss 2.0.5
jake
HiThanks to your answer.But I tried it in ver 2.0.3 it s not working that I expected.That suppsose 3. param like parameter. (Like tablecollection.Where(Table.Columns.Val1, comp, 5);and generate sql like below/* GetSelectSql(Table1) */ SELECT TOP 100 PERCENT [dbo].[Table1].[ID], [dbo].[Table1].[Val1], [dbo].[Table1].[Val2] FROM [dbo].[Table1] WHERE [Table1].[Val1] = @Val20 ORDER BY [ID] ASC;are you tired in 2.0.3 ?
A: 
private void CreateDynamicControls()
{


 panGvHolder.Controls.Clear();

 Query qry = Northwind.Product.CreateQuery();
 qry.Columns.AddRange(Northwind.Product.Schema.Columns);
 qry.WHERE("UnitPrice > 15").AND("UnitsInStock < 20 ");
 //WHERE("UnitPrice > 15").AND("UnitsInStock < 30 ");



 using (IDataReader rdr = qry.ExecuteReader())
 {
  Response.Write("<table>");
  while (rdr.Read())
  {
   Response.Write("<tr>");
   for (int i = 0; i < rdr.FieldCount; i++)
   {
    Response.Write("<td>");
    Response.Write(rdr[i].ToString() + " ");
    Response.Write("<td>");
   } //eof for 
   Response.Write("</br>");
   Response.Write("</tr>");
  }
  Response.Write("<table>");
 }
} //eof method
YordanGeorgiev