实体框架Web API - 使用外键值获取相关实体

时间:2017-04-06 12:02:32

标签: entity-framework asp.net-web-api2

我有两张表for(i = 0; i < nodeChild.length; ++i) { if(ThePlayerName != nodeChild[i].id) { MyChildPropertie = nodeChild[i].style.left; MyChildPropertie = parseInt(MyChildPropertie.substring(0,(MyChildPropertie.length - 2))); MyChildPropertie += -15; if(nodeChild[i].PlayerPart != 'yup'){ nodeChild[i].style.left = MyChildPropertie + "px"; } } } Round。一轮比赛有很多比赛,我想使用网络API获得一轮比赛的所有比赛。

以下是我的课程(为了这个问题而简化)

Game

我希望能够使用实体框架传递一个圆形ID并从该轮获得所有游戏。

1 个答案:

答案 0 :(得分:1)

如果您没有启用延迟加载,include该回合中包含的游戏。如果启用了延迟加载,则不需要include

Games可以通过其导航属性访问(假设在EF模型中正确设置了关系)。

Guid roundId;    
var roundWithGames = dbContext.Rounds.Include(r => r.Games).SingleOrDefault(r => r.Id == roundId);
if (roundWithGames == null) { throw new ArgumentException(nameof(roundId)); }
var gamesOfRound = roundWithGames.Games;
相关问题