使用Where无效的Linq查询

时间:2011-07-24 04:58:12

标签: c# linq

我有以下代码:

    public ActionResult Details(int orderId)
    {
        var query = from orderDetails in storeDb.OrderDetails
                    where orderDetails.OrderId = orderId
                    select new { orderDetails.Product, orderDetails.Quantity, orderDetails.UnitPrice };

        return View(query);
    }

我想得到orderDetails的行,其中外键OrderId等于参数orderId。但是我不断收到以下错误:Error 2 Cannot implicitly convert type 'int' to 'bool'。我错过了什么?

2 个答案:

答案 0 :(得分:8)

where orderDetails.OrderId = orderId

需要

where orderDetails.OrderId == orderId

答案 1 :(得分:0)

where orderDetails.OrderId == orderId