Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:08:39+00:00 2026-06-06T23:08:39+00:00

I am trying to do a search using QueryOver however the results returned, although

  • 0

I am trying to do a search using QueryOver however the results returned, although are right based on the search criteria, are being duplicated.

Here is the code I am using to count the results, which works correctly

// 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();

If I change the last line to a select statement with skip and take like so

return returned.OrderBy(x => x.CreatedUTC).Desc.Skip(skip).Take(take).List<Note>();

Then I get the 3 notes back, instead of 2. 1 note is duplicated, while the other is ok. I can only assume that is because the query matched two of the tags linked to one note.

The SQL outputted by nHibernate profiler is as follows

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

If I put this directly into SQL management studio it returns 3 results, two of which are the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:08:40+00:00Added an answer on June 6, 2026 at 11:08 pm

    That’s because of the left join, which causes a cartesian product. You should apply the DistinctRootTransformer by appending this:

    .TransformUsing(Transformers.DistinctRootEntity)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create pagination for search results using MySQL and ColdFusion. My intention
I'm trying to search for people based on their skills by using different keywords.
I'm trying to search tweets using search method in twitter4j. My code is as
I'm trying to implement search code in my CoreData-based iPhone app. I'm not sure
I'm trying to do a google search using Ruby, and print the 1st 3
I'm trying using NHibernate.Search to get Lucene.NET Score through projections. My domain object implements
I'm trying to search the Stack Overflow questions using the php stacks app But
I am trying to implement depth first search algorithm using adjacency list representation of
I am trying to make a search function using the combination of DOM, PHP
I am trying to build a search engine using java and the lucene API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.