为什么 .Fetch() 会抛出空引用异常?

发布于 2024-11-18 06:06:28 字数 506 浏览 7 评论 0原文

我有以下 nhibernate linq 查询,它抛出空引用异常

promotions = (from a in session.Query<Application>()
                          from ap in a.Promotions
                          where a.Id == applicationId
                          && ap.EndDate >= DateTime.Now && ap.StartDate <= DateTime.Now
                          select ap).Fetch(ap => ap.LandingPage).ToList();

没有 .Fetch() 的相同查询工作正常。我两次都传递相同的 id,所以这不是数据问题。

这是一个错误,还是设计使然?我怎样才能让它不抛出异常?

I have the following nhibernate linq query and it throws a null reference exception

promotions = (from a in session.Query<Application>()
                          from ap in a.Promotions
                          where a.Id == applicationId
                          && ap.EndDate >= DateTime.Now && ap.StartDate <= DateTime.Now
                          select ap).Fetch(ap => ap.LandingPage).ToList();

The same query without the .Fetch() works fine. I am passing the same id both times, so it's not a data issue.

Is this a bug, or by design? How can I make it not throw an exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘你却要生生世世 2024-11-25 06:06:28

如果将 .Fetch(ap => ap.LandingPage) 移至声明之后,会改变结果吗?

from ap in a.Promotions.Fetch(ap => ap.LandingPage)

If you move the .Fetch(ap => ap.LandingPage) to immediately after the declaration does that change the outcome?

from ap in a.Promotions.Fetch(ap => ap.LandingPage)
人生戏 2024-11-25 06:06:28
from a in session.Query<Application>().Fetch(ap => ap.LandingPage)
//the rest of your code
from a in session.Query<Application>().Fetch(ap => ap.LandingPage)
//the rest of your code
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文