0
我正在製作購物車,點擊Add to cart
後,用戶被重定向到一個頁面,該頁面接受產品的id
作爲GET
參數,並基於此我想要檢索其價格,我喜歡這樣有EF:從表中獲取小數點
decimal price = Convert.ToDecimal(db.Products.Where(x => x.Id == productId).Select(x => x.Price));
然而,當我點擊Add to cart
並擊中其重定向到URL,我得到這個錯誤在VS:
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[System.Decimal]' to type 'System.IConvertible'.
我是新來.NET
所以我可能不被檢索以正確的方式來評價價格。