EF4: LINQ 2 Entities query works in C# but not in VB

后端 未结 4 443
滥情空心
滥情空心 2021-02-03 13:53

[EDITED: I left the original question below, with some more context and code to reproduce the problem. The short version below contains the essence of the question]

Shor

4条回答
  •  误落风尘
    2021-02-03 14:51

    Moving the Order By p.DateCreated line as per my edited answer allows the query to run without any exceptions. However, the emitted SQL is different so I don't think you are getting back the correct result.

    Dim qLinq = From outerOrder In orders
                Let id = (From p In products 
                          Order By p.DateCreated
                          Join o In orders On p.Id Equals o.ProductId
                          Where o.OrderDate = outerOrder.OrderDate AndAlso
                                outerOrder.CustomerId = o.CustomerId
                          Select p.Id).FirstOrDefault()
                Where outerOrder.OrderDate = currentDate AndAlso
                      outerOrder.ProductId = id
                Select outerOrder
    

提交回复
热议问题