tags:

views:

359

answers:

5

Hi,

I am new with SubSonic and have a problem with query. This is my query string

string sql = "SELECT *" +
             " FROM tbl_exrates, tbl_currency" +
             " WHERE date = " + d;
             " AND tbl_exrates.currency = tbl_currency.cid" +
             " AND (cash > 0 OR transfer > 0 OR sell > 0)";

How to convert it to SubSonic Query string ? Does SS have function support to do that ?

Thanks !

+1  A: 

It appears you can do quick complicated queries in Subsonic:

http://subsonicproject.com/querying/select-queries/

Jonathan Parker
+1  A: 

You should follow this link. It has all the select queries you are looking for.

CodeToGlory
+1  A: 
q = new Select("*").From(TblExrate.Schema)
            .InnerJoin(TblCurrency.Schema)
            .WhereExpression("date").IsEqualTo(d)
            .AndExpression("cash").IsGreaterThan(0)
            .Or("transfer").IsGreaterThan(0)
            .Or("cash").IsGreaterThan(0);

Please help me check the code above, is it correct ?

Thanks !

Shinichi
+3  A: 
q = new Select().From(TblExrate.Schema)
        .InnerJoin(TblCurrency.Schema)
        .Where(tbl_exrates.date).IsEqualTo(d)
        .AndExpression(tbl_exrates.cash).IsGreaterThan(0)
        .Or(tbl_exrates.transfer).IsGreaterThan(0)
        .Or(tbl_exrates.cash).IsGreaterThan(0);
Adam
This a great answer, as long as readers remember that SubSonic infers the relationship between TblExrate and TblCurrency based on the existence of a foreign key. I forget what happens if the foreign key doesn't exist--does the query fail?
ranomore
I'm sure it will fail, although I don't know how exactly.
Adam
A: 
q = new Select().From(TblExrate.Schema)
                .InnerJoin(TblCurrency.Schema)
                .Where(TblExrate.Columns.DateX).IsEqualTo(d)
                .And(TblExrate.Columns.Currency).IsEqualTo(TblCurrency.Columns.Currency)
                .AndExpression(TblExrate.Columns.Cash).IsGreaterThan(0)
                .Or(TblExrate.Columns.Transfer).IsGreaterThan(0)
                .Or(TblExrate.Columns.Sell).IsGreaterThan(0);

I try another query like above and get error : "Input string was not in a correct format.". Please tell me where is error ?

Thanks !

Shinichi
The error is here:.And(TblExrate.Columns.Currency).IsEqualTo(TblCurrency.Columns.Currency)
Adam
Hi,I knew it, too ! However, I don't know how to correct it ! I tried.And(TblExrate.Columns.Currency = TblCurrency.Columns.Currency)But still error !Thanks !
Shinichi
Call q.BuildSqlStatement() and check the return value. It should show you something like "and dbo.TblExRate.Currency = 'Currency'". SubSonic doesn't handle column comparisons like this except in the InnerJoin() method. Try "InnerJoin(TblExrate.CurrencyColumn, TblCurrency.CurrencyColumn)" instead.
ranomore
I 've done it ! Thanks alot ! :-)
Shinichi