2009-05-21 76 views
0

我想達到與亞音速2.2執行與在

SELECT Product.* FROM Product WHERE Product.OurPrice <> Product.RetailPrice 

亞音速選擇查詢下面的SQL語句單一選擇我已經開始與:

SubSonic.SqlQuery select = new SubSonic.Select() 
.From<Product>() 
.Where(Product.Columns.OurPrice) 
.IsNotEqualTo(... object /*Should be Product.Columns.RetailPrice, but that's giving and exception*/...); 

我的問題是如何告訴SubSonic 2.2針對同一個表中的另一列生成where條件。

+0

你什麼異常? – 2009-05-21 13:19:32

+0

異常(片段)是 [出現FormatException:輸入字符串的不正確的格式。] System.Number.StringToNumber(字符串str的NumberStyles選項,NumberBuffer和數量,信息的NumberFormatInfo,布爾parseDecimal)7469351 ... [FormatException:無法將參數值從字符串轉換爲十進制。] System.Data.SqlClient.SqlParameter.CoerceValue(Object value,MetaType destinationType)+4872143 ... [SqlQueryException:無法將參數值從一個字符串轉換爲十進制字符串到十進制。] SubSonic.SqlQuery.ExecuteReader()+57 SubSonic.SqlQuery.ExecuteAsCollection()+80 – csizo 2009-05-21 13:24:19

+0

什麼是價格的列類型?他們可以有非數字數據或'$'? – 2009-05-21 15:00:54

回答

0

爲上述問題的解決方案:

ProductCollection products = new SubSonic.InlineQuery().ExecuteAsCollection<ProductCollection> 
(@"SELECT Product.ProductId, ... Product.ModifiedBy, Product.ModifiedOn, Product.IsDeleted FROM Product WHERE (Product.OurPrice <> Product.RetailPrice)"); 

Repeater1.DataSource = products; 
Repeater1.DataBind(); 
0

您可以使用舊的查詢對象(仍包含在2.2),像這樣:

Query q = new Query(Product.Schema.TableName).WHERE("OurPrice <> RetailPrice"); 
ProductCollection products = new ProductCollection(); 
products.LoadAndCloseReader(q.ExecuteReader());