我尝试自定义*1
执行的查询,但以下代码class DefaultContentManager
{
...
public virtual ContentItem Get(int id, VersionOptions options, QueryHints hints) {
...
// implemention of the query comes here
...
*1 -> // no record means content item is not in db
if (versionRecord == null) {
// check in memory
var record = _contentItemRepository.Get(id);
if (record == null) {
return null;
}
versionRecord = GetVersionRecord(options, record);
if (versionRecord == null) {
return null;
}
}
让我的努力变得毫无用处:
*1
查询正确执行并且它不返回任何数据(这是我的目标),但之后执行第二次尝试check in memory
仍然获取内容项。
为什么这部分代码在那里?它的目的是什么?另外,为什么要查询注释状态retval = Shell("plink perl test.pl")
,然后查询存储库(数据库表)。
答案 0 :(得分:4)
此时已经验证该项目在数据库中不存在,但可能是在同一请求期间从代码创建的。在这种情况下,nHibernate会话有项目,但数据库还没有。存储库会命中会话,而不是直接访问数据库,所以如果它存在,它将检索它,但这将在内存中发生。