2014-10-04 60 views
0

我是新來的MongoDB和寫我的第一EntitySetController訪問我的樣本數據。我的問題是,是否有相當於MongoDB中的導航屬性?我正在嘗試在我的GET方法中使用Include,但沒有任何運氣。這裏是我的代碼到目前爲止:MongoDB的導航性能

Team object : 

public class Team 
    { 
     [BsonId] 
     [BsonRepresentation(BsonType.ObjectId)] 
     public string Id { get; set; } 
     public string TeamName { get; set; } 
     public string BadgeSmall { get; set; } 
     public string BadgeLarge { get; set; } 
     public string TeamImage { get; set; } 
     public string Formation { get; set; } 
    } 

Fixture object : 

public class Fixture 
    { 
     [BsonId] 
     [BsonRepresentation(BsonType.ObjectId)] 
     public string Id { get; set; } 
     public DateTime FixtureDate { get; set; } 
     [BsonRepresentation(BsonType.ObjectId)] 
     //foreign key 
     public string AwayTeamId { get; set; } 
     //navigation properties 
     public virtual Team AwayTeam { get; set; } 
     [BsonRepresentation(BsonType.ObjectId)] 
     //foreign key 
     public string HomeTeamId { get; set; } 
     //navigation properties 
     public virtual Team HomeTeam { get; set; } 
     public byte? AwayTeamScore { get; set; } 
     public byte? HomeTeamScore { get; set; } 

     public string AwayTeamScorers { get; set; } 
     public string HomeTeamScorers { get; set; } 
    } 

Fixture controller : 

[EnableQuery] 
     public IQueryable<Fixture> GetFixtures() 
     { 
      IQueryable<Fixture> m = mongoDatabase.GetCollection<Fixture>("Fixtures").FindAll().AsQueryable().Include("HomeTeam").Include("AwayTeam"); 

      return m; 
     } 

回答

0

不,沒有導航屬性的概念。由於MongoDB不支持連接,這意味着我們必須至少進行2次遠程調用才能爲您的實體提供保溼功能。我們希望你明確這一點,因爲你有可能簡單地對數據進行不同的模型建模,這樣你就可以用一個查詢來完成。

例如,你的情況可能是你不僅應該在你的Fixture中有HomeTeamId和AwayTeamId,而且還有一些非規範化數據的子集,以便你不需要第二個查詢。