好吧,我會在這裏寫下我最終做的事情,這看起來不是一個完美的解決方案,但在這種情況下似乎並沒有任何完美的解決方案。
As Ladislav指出,ExecuteStoreQuery
(以及其他「自定義查詢」方法,Translate
)只映射您指定的實體的列,而將所有其他列留在一邊。因此,我不得不單獨加載相關性,如下所示:
// Execute
IEnumerable<MainEntity> result = context.ExecuteStoreQuery<MainEntity>(strQuery, "MainEntities", MergeOption.AppendOnly, someParams).ToArray();
// Load relations, first method
foreach (MainEntity e in result)
{
if (!e.Relation1Reference.IsLoaded)
e.Relation1Reference.Load();
if (!e.Relation2Reference.IsLoaded)
e.Relation2Reference.Load();
// ...
}
// Load relations, second method
// The main entity contains a navigation property pointing
// to a record in the OtherEntity entity
foreach(OtherEntity e in context.OtherEntities)
context.OtherEntities.Attach(e);
那裏。我認爲這兩種技術必須根據生成請求的數量和大小來選擇。第一種技術會爲每個需要的邊記錄生成一個記錄請求,但不會加載任何不安全的記錄。第二種技術使用較少的請求(每個表一個),但檢索所有記錄,以便使用更多內存。
該屬性看起來很挑剔。如果您在「選擇」中有一列,並且該屬性不在該實體上,它不會那樣。 (「我期待這一點)。如果對象中有一個屬性不在「結果」中,則它不會那樣。 (「我不期待這個) – granadaCoder 2014-01-07 22:18:18