我有一个父对象(季节)的回购设置。该季节对象包含一个子对象(日程表)。然后该对象有一个名为Match的子对象。Repo queryable只返回前2条记录的行
当通过
season.Schedules.AsQueryable().Where(s => s.Week == 1).ToList();
这只是返回“匹配”的记录为第2个时间表检索记录。如果我去SSMS,它会返回所有时间表的“匹配”记录。
下面是对象的映射:
季节:
HasMany(x => x.Schedules).KeyColumn("SeasonId");
附表:
HasOne(x => x.Match).ForeignKey("MatchId");
这是我的观点,我尝试遍历的比赛,其中第2工作,并且所有其余的“匹配”对象都为空(但是当它们在SSMS中“查询”时填充它们。
@model LeagueManager.Models.MatchModel
@foreach (var schedule in Model.Schedules.Where(s => s.Week == 1))
{
<div class="row">@schedule.Match.MatchResults25Game.Game1.PlayerA.DisplayName vs @schedule.Match.MatchResults25Game.Game1.PlayerB.DisplayName</div>
<div class="row">@schedule.Match.MatchResults25Game.Game2.PlayerA.DisplayName vs @schedule.Match.MatchResults25Game.Game2.PlayerB.DisplayName</div>
<div class="row">@schedule.Match.MatchResults25Game.Game3.PlayerA.DisplayName vs @schedule.Match.MatchResults25Game.Game3.PlayerB.DisplayName</div>
<div class="row">@schedule.Match.MatchResults25Game.Game4.PlayerA.DisplayName vs @schedule.Match.MatchResults25Game.Game4.PlayerB.DisplayName</div>
........
}
有什么方法可以帮助我找出为什么它没有返回所有的“匹配”值,或者是我的所有设置有什么问题(我不会这么认为,因为前两条记录来返回ok ...)
让我知道是否需要更多的背景信息。
UPDATE
这是我从快递探查获得:
exec sp_executesql N'
SELECT schedules0_.SeasonId as SeasonId2_,
schedules0_.ScheduleId as ScheduleId2_,
schedules0_.ScheduleId as ScheduleId12_1_,
schedules0_.Week as Week12_1_,
schedules0_.MatchNumber as MatchNum3_12_1_,
schedules0_.MatchDate as MatchDate12_1_,
schedules0_.SeasonId as SeasonId12_1_,
schedules0_.TeamA as TeamA12_1_,
schedules0_.TeamB as TeamB12_1_,
match1_.MatchId as MatchId3_0_,
match1_.MatchResults25GameId as MatchRes2_3_0_
FROM Schedule schedules0_
left outer join Match match1_ on schedules0_.ScheduleId=match1_.MatchId
WHERE [email protected]',N'@p0 int',@p0=1
go
看看NHibernate生成的SQL,然后告诉我们,你需要什么SQL。 – Rippo
作为一般性考虑,您的视图只能与ViewModel对象进行交互,而不能与任何DB Repository进行交互。也许这正是你在做什么,只击中已经加载在显存逻辑中的对象。这可以解释为什么你从数据库中获得不同的结果tahn – jbl
你确定你在计划和匹配(HasOne)之间有一对一的关系吗?如果不是,我会用'References'代替'HasOne'(多对一) – rivarolle