servicestack ormlite 总是返回匿名对象,即使没有找到

servicestack ormlite always returning anonymous object, even if not found

我创建了一个连接多个表的查询,末尾有一个 where,最终表被映射到 ormlite 自述文件中推荐的自定义数据模型。

using (var db = _connectionFactory.Open()) {
            var q = db.From<PlayerMatch>()
                        .Join<PlayerMatch, Player>((x, y) => x.PlayerId == y.Id)
                        .Join<PlayerMatch, Team>((x, y) => x.TeamId == y.Id)
                        .Join<PlayerMatch, Match>((x, y) => x.MatchId == y.Id)
                        .Join<PlayerMatch, Goal>((x, y) => x.Id == y.PlayerMatchId)
                        .Where<PlayerMatch>(x => x.MatchId == matchId)
                        .Select<PlayerMatch, Player, Team, Match, Goal>((pm, p, t, m, g) =>  new { PlayerMatchId = pm.Id, PlayerId = p.Id, TeamId = t.Id, MatchId = m.Id, TotalGoalsScored = Sql.Count(g.Id) } );


var result = await db.SelectAsync<PlayerMatchEndResult>(q);
result.PrintDump();
return result;

然而,在我的测试中,我发现即使 where 子句中的 matchid 是 none 现有的,它仍然 return 给我以下数据模型:

PlayerMatchEndResult
{
  MatchId = 0
  PlayerId = 0
  PlayerMatchId = 0
  TeamId = 0
  TotalGoalsScored = 0
}

如您所见,由于找不到相应的记录,它将匿名对象的所有属性默认为 0,因此 returning 一个无效对象。

我想要它 return 什么都没有(空)所以我可以根据空检查而不是比较来检查记录是否存在 if id == 0。

ormlite 可以吗?

Enabling logging 按照 mythz 的建议解决了我的问题。