Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nhibernate QueryOver Select返回的结果多于Count_Nhibernate_Queryover - Fatal编程技术网

Nhibernate QueryOver Select返回的结果多于Count

Nhibernate QueryOver Select返回的结果多于Count,nhibernate,queryover,Nhibernate,Queryover,我正在尝试使用QueryOver进行搜索,但是返回的结果(尽管基于搜索条件是正确的)正在被复制 下面是我用来计算结果的代码,它工作正常 // disjunction to find query string in note text of tag list var disjunction = new Disjunction(); disjunction.Add(Restrictions.On<Note>(e => e.Text).IsInsensitiveLike(query)

我正在尝试使用QueryOver进行搜索,但是返回的结果(尽管基于搜索条件是正确的)正在被复制

下面是我用来计算结果的代码,它工作正常

// disjunction to find query string in note text of tag list
var disjunction = new Disjunction();
disjunction.Add(Restrictions.On<Note>(e => e.Text).IsInsensitiveLike(query));

var tagSubQuery = QueryOver.Of<Note>().JoinQueryOver(x => x.Tags).Where(x => x.Text.IsInsensitiveLike(query)).Select(x => x.Id);
disjunction.Add(Subqueries.WhereProperty<Note>(x => x.Id).In(tagSubQuery));

// find notes between dates and based on disjunction
var notes = this.DataOver.Where(x => x.CreatedUTC >= startDate && x.CreatedUTC <= endDate).Where(disjunction);

// only show notes within permitted accounts
var subnotes = QueryOver.Of<Note>().JoinQueryOver(x => x.Accounts).Where(x => x.Company.Id == user.Company.Id).Select(x => x.Id);
var returned = notes.WithSubquery.WhereProperty(x => x.Id).In(subnotes);

return returned.RowCount();
如果我用skip和take-like将最后一行更改为select语句

return returned.OrderBy(x => x.CreatedUTC).Desc.Skip(skip).Take(take).List<Note>();
然后我取回3个音符,而不是2个。1个注释重复,而另一个注释正常。我只能假设这是因为查询匹配了链接到一张便笺的两个标记

nHibernate探查器输出的SQL如下

SELECT TOP (20 /* @p0 */) this_.Id           as Id47_1_,
                 this_.CreatedGMT   as CreatedGMT47_1_,
                 this_.CreatedLocal as CreatedL3_47_1_,
                 this_.CreatedUTC   as CreatedUTC47_1_,
                 this_.UpdatedGMT   as UpdatedGMT47_1_,
                 this_.UpdatedLocal as UpdatedL6_47_1_,
                 this_.UpdatedUTC   as UpdatedUTC47_1_,
                 this_.CreatedBy    as CreatedBy47_1_,
                 this_.UpdatedBy    as UpdatedBy47_1_,
                 this_.Text         as Text47_1_,
                 this_.UserId       as UserId47_1_,
                 this_.Suppress     as Suppress47_1_,
                 tags2_.NoteId      as NoteId3_,
                 tag3_.Id           as TagId3_,
                 tag3_.Id           as Id27_0_,
                 tag3_.CreatedGMT   as CreatedGMT27_0_,
                 tag3_.CreatedLocal as CreatedL3_27_0_,
                 tag3_.CreatedUTC   as CreatedUTC27_0_,
                 tag3_.UpdatedGMT   as UpdatedGMT27_0_,
                 tag3_.UpdatedLocal as UpdatedL6_27_0_,
                 tag3_.UpdatedUTC   as UpdatedUTC27_0_,
                 tag3_.CreatedBy    as CreatedBy27_0_,
                 tag3_.UpdatedBy    as UpdatedBy27_0_,
                 tag3_.Text         as Text27_0_
FROM   [dev.Client].[dbo].Note this_
       left outer join [dev.Client].[dbo].TagToNote tags2_
         on this_.Id = tags2_.NoteId
       left outer join [dev.Client].[dbo].Tag tag3_
         on tags2_.TagId = tag3_.Id
WHERE  this_.Id in (SELECT this_0_.Id as y0_
                    FROM   [dev.Client].[dbo].Note this_0_
                           inner join [dev.Client].[dbo].NoteToAccount accounts3_
                             on this_0_.Id = accounts3_.NoteId
                           inner join [dev.Client].[dbo].Account account1_
                             on accounts3_.ClientAccountId = account1_.Id
                    WHERE  this_0_.Id in (SELECT this_0_0_.Id as y0_
                                          FROM   [dev.Client].[dbo].Note this_0_0_
                                          WHERE  (this_0_0_.CreatedUTC >= '2012-06-01T00:00:00.00' /* @p1 */
                                                  and this_0_0_.CreatedUTC <= '2012-06-30T00:00:00.00' /* @p2 */)
                                                 and (lower(this_0_0_.Text) like '%dtes%' /* @p3 */
                                                       or this_0_0_.Id in (SELECT this_0_0_0_.Id as y0_
                                                                           FROM   [dev.Client].[dbo].Note this_0_0_0_
                                                                                  inner join [dev.Client].[dbo].TagToNote tags3_
                                                                                    on this_0_0_0_.Id = tags3_.NoteId
                                                                                  inner join [dev.Client].[dbo].Tag tag1_
                                                                                    on tags3_.TagId = tag1_.Id
                                                                           WHERE  lower(tag1_.Text) like '%dtes%' /* @p4 */)))
                           and account1_.CompanyId = 1 /* @p5 */)
ORDER  BY this_.CreatedUTC desc

如果我将其直接放入SQL management studio,它将返回3个结果,其中两个结果相同。

这是因为左连接导致笛卡尔积。应通过附加以下内容应用distinctrouttransformer:


.TransformingTransformers.DistincTroutenty

在人际关系方面,我不是100%,但这似乎起到了作用。非常感谢。