我已經使用Silverlight RIA服務在EF Code First中嵌套對象,我能夠在服務端獲取數據,但是當我在客戶端看到它的子對象爲null 。你能指導我什麼是錯的。代碼優先在客戶端的嵌套對象空EF RIA服務
[HasSelfValidation]
public class Batch
{
public int BatchId { get; set; }
public string BatchName { get; set; }
[Include]
[Composition]
[Association("FK_Batch_BathSetItemSet", "BatchId", "BatchSetIdItemSetId")]
public virtual ICollection<BatchSetItemSet> BatchSetItemSets { get; set; }
}
public class BatchSetItemSet
{
public int BatchSetIdItemSetId { get; set; }
public int BatchId { get; set; }
public Nullable<int> ItemSetId { get; set; }
public string CreatedBy { get; set; }
public Batch Batch { get; set; }
[Include]
[Composition]
[Association("FK_BathSetItemSet_ItemSet", "BatchSetIdItemSetId", "ItemSetId")]
public ItemSet ItemSet { get; set; }
}
public class ItemSet
{
public int ItemSetId { get; set; }
public int CustodianId { get; set; }
public string ItemSetName { get; set; }
public virtual ICollection<BatchSetItemSet> BatchSetItemSets { get; set; }
[Include]
[Composition]
[Association("FK_ItemSet_Custodian", "ItemSetId", "CustodianId")]
public virtual Custodian Custodian { get; set; }
}
和服務電話是:this.DbContext.Batches.Include("BatchSetItemSets.ItemSet.Custodian").Where(x => x.BatchId == batchId).SingleOrDefault();
你是如何加載你的實體客戶端?請發送代碼 – mCasamento
對不起,我沒有正確地得到您的問題,我有WCF RIA服務,我打電話使用以下調用:this.DbContext.Batches.Include(「BatchSetItemSets.ItemSet.Custodian」)。其中(x = > x.BatchId == batchId).SingleOrDefault(); – Deepak