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 724029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:10:32+00:00 2026-05-14T06:10:32+00:00

I´m having some trouble retrieving a collection of strings in a projection: say that

  • 0

I´m having some trouble retrieving a collection of strings in a projection:
say that I have the following classes

public class WorkSet {
    public Guid Id { get; set; }
    public string Title { get; set; }
    public ISet<string> PartTitles { get; protected set; }
}
public class Work {
    public Guid Id { get; set; }
    public WorkSet WorkSet { get; set; }
    //a bunch of other properties
}

I then have a list of Work ids I want to retrieve WorkSet.Title, WorkSet.PartTitles and Id for.

My tought was to do something like this:

            var works = Session.CreateCriteria<Work>()
            .Add(Restrictions.In("Id", hitIds))
            .CreateAlias("WorkSet", "WorkSet")
            .SetProjection(
            Projections.ProjectionList()
                .Add(Projections.Id())
                .Add(Projections.Property("WorkSet.Title"))
                .Add(Projections.Property("WorkSet.PartTitles")))
            .List();

The Id and Title loads up just fine, but the PartTitles returns null.
Suggestions please!

  • 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-05-14T06:10:33+00:00Added an answer on May 14, 2026 at 6:10 am

    This might not work using criteria. Most probably, it is because the set can not be retrieved by the same sql query that is generated by the criteria.

    I would actually really consider to retrieve the whole object. It is much easier and if it is not a very very special case, it is not worth the troubles. (By the way, it could be faster to retrieve whole objects, the may be already in the cache.) What usually counts is the number of queries (and its complexity of course), not the number of columns retrieved.

    It probably works with HQL, there is a elements function there. Consider to use HQL for static queries anyway, it is more powerful.

    select 
      ws.Title, 
      elements(ws.PartTitles), 
      w.id
    from 
      Work w 
      inner join w.WorkSet ws
    where w.id in (:ids)
    

    elements is allowed in the select clause, but I don’t know what you’ll get. You most probably get as many records as there are PartTitles in the result, because there is only one SQL statement built.

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

Sidebar

Related Questions

Having some trouble with R's garbage collection, when passing objects to C++. We have
Having some trouble looping through these arrays , i have 4 properties that identical
Having some trouble with the following code. I've created a class to manage the
Having some trouble passing values from one class to another. I basically have a
Having some trouble getting this right, I have a list of transaction that I
I've been having some trouble retrieving text of a table cell that is clicked,
I have been having some trouble with the facebook SDK, specifically retrieving an access
So having some trouble with a class methods. I'll post all the information that
Im having some trouble writing a getstring function, this is what I have so
Having some trouble understanding the right approach here. I have a connection to a

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.