2012-03-14 81 views
0

我有一個WCF的DataService具有以下CodeFirst型號:WCF DataService的Silverlight的+ +實體框架CodeFirst模型對象爲空

public class Project 
{ 
    public int ProjectID { get; set; } 
    public string Name { get; set; } 

    public virtual Owner Owner { get; set; } 
} 

public class Owner 
{ 
    public int OwnerID { get; set; } 

    public string FirstName { get; set; } 
    public string LastName { get; set; } 
} 

我也有支持類SchedulerContextSchedulerContextInitializerSchedulerService.svc標準。我的服務如下所示:

我添加了服務引用到我的Silverlight項目中。我可以在瀏覽器中瀏覽服務並查看我的種子數據。當我去http://localhost:31560/SchedulerService.svc/Projects(1)/Owner時,我可以看到我的種子數據。然而,當我的項目負荷在我的Silverlight數據訪問類:

public class SchedulerService : ISchedulerService 
{ 
    public SchedulerService() 
    { 
     var context = new SchedulerContext(new Uri("/SchedulerService.svc", UriKind.Relative)); 

     this.Projects = new DataServiceCollection<Project>(); 
     DataServiceQuery<Product> query = context.Projects; 
     this.Projects.LoadAsync(query); 
    } 

    public DataServiceCollection<Project> Projects { get; private set; } 
} 

每個項目的業主是總是空!我該如何解決?!

回答

1

您是否嘗試過:

context.Projects.Expand("Owner"); 
+0

這是它,謝謝!如果任何人有興趣,我還發現一種方法來避免[ODataMuscle]中的「魔術字符串」(http://elegantcode.com/2010/10/17/odatas-dataservicequery-and-removing-the-expandmagicstrings-part-ii/ )。 – Pakman 2012-03-15 20:19:25

相關問題