所以我有2個表Comments
和Students
。每一個評論有一個學生: Comment.StudentId
ASP.NET - SQL - 檢索'包含'對象
我使用POCO生成的類,它似乎給我的評論類中整個Student對象時,我進行查詢,像這樣:
var query =
from comment in context.Comments
where comment.StudentId == properId
orderby comment.Created
select comment;
所以我可以訪問像這樣comment.Student.Name
但是學生的屬性,當我複製的結果(query.ToList()
的方法外使用,它給了我一個錯誤說的ObjectContext的實例被佈置。
如何從包含在對象中的對象檢索數據?
IOrderedQueryable似乎並不具備該功能 – TheAJ
從context.Comments.Include評論( 「學生」) –