1
我試圖在.NET 4中使用實體框架4.1來完成以下工作;由一個實體框架的多方訂購
var context = new MyEntities();
var results = context.Diners
.OrderBy(i => i.MenuItems.Course.DisplayOrder)
.ThenBy(i => i.MenuItems.DisplayOrder);
這裏的問題是,是的MenuItems的對象集(集)和集合沒有一個場(另一個連接表)。一個MenuItem(單數)有一個過程。希望這是顯而易見的。
以下是我用來做這件事的SQL;
Select
*
From
Diner As D
Inner Join
DinerSelection As DS -- This is the Many to Many that EF has abstracted away.
On D.DinerId = DS.DinerId
Inner Join
MenuItem As MI
On DS.MenuItemId = MI.MenuItemId
Inner Join
Course As C
On MI.CourseId = C.CourseId
Order By
C.DisplayOrder, MI.DisplayOrder
如果在EF中做這件事不是一件容易的事情,那麼我只是將它視爲一種觀點,儘管我寧願不這樣做。