2015-08-14 32 views
0

在執行查詢我面臨的一個錯誤:附近有語法錯誤 'B'

附近有語法錯誤 'B'

代碼:

using(var db = new GnpCoreDatabase()) 
      { 
       var basket = db.Query<Basket> 
("select p.product_tax,c.shipping_cost FROM dbo.Basket b 
join dbo.CompanyProducts cp b.CompanyProduct_Id = cp.Product_Id 
join dbo.products p on p.Product_Id = cp.Product_Id 
join dbo.Company c on c.company_Id = cp.Company_Id 
where b.Added_by [email protected]", 1).Select(x => new Basket() { 
       Tax = x.Tax, 
       ShippingCost = x.ShippingCost, 
       IsSuccessfull = true 
       }).SingleOrDefault(); 
       basket.Items = GetAllItems(); 
       return basket; 
      } 

我不明白爲什麼會發生此錯誤。我在數據庫中運行這個查詢併產生結果。

+5

也許你需要在你的第一個'join'線使用關鍵字'on',在'b.CompanyProduct_Id'之前。 – halfbit

+1

@halfbit:不是「也許」;) –

回答

2

你錯過了在第一次JOINON關鍵字:

select p.product_tax,c.shipping_cost 
FROM dbo.Basket b 
     join dbo.CompanyProducts cp ON b.CompanyProduct_Id = cp.Product_Id 
     join dbo.products p on p.Product_Id = cp.Product_Id 
     join dbo.Company c on c.company_Id = cp.Company_Id 
where b.Added_by [email protected]