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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:24:37+00:00 2026-05-25T11:24:37+00:00

I have a simple model, consisting of a document that references one or more

  • 0

I have a simple model, consisting of a document that references one or more article using a reference object (this is because in the domain, we do not own the articles so we can only reference them).

I’m trying to write a query that lists the documents, printing the ID and a string consisting of a comma separated list of article numbers. For example:

ID ARTICLES
------------------
1  ACC, PE2,
2  ER0, AQ3, FEE
3  PE2

My problem is with selecting the comma separated list.

Here are the domain classes:

// The Entity class has an Id property.
public class Document : Entity
{
    public virtual IEnumerable<ArticleReference> ArticleReferences { get; set; }
    public virtual DateTime ReceiveDate { get; set; }
}

// The ValueObject does not have an Id property ofcourse.
public class ArticleReference : ValueObject
{
    public virtual string ArticleNumber { get; set; }
    public virtual string ArticleName { get; set; }
}

The article reference is a value object so it does not have an ID of its own.

This is the view model that represents an item in the result list:

public class DocumentListItemModel
{
    public int Id { get; set; }
    public string ArticleNumbers { get; set; }
    public string ReceiveDate { get; set; }
}

And here’s the query class I have come up with so far:

public class DocumentQuery
{
    public IList<DocumentListItemModel> ExecuteQuery()
    {
        IntermediateModel model = null;
        ArticleReference articleReferenceAlias = null;

        return Session
            .QueryOver<Document>()
            .JoinAlias(n => n.ArticleReferences, () => articleReferenceAlias);
            .SelectSubQuery(
                QueryOver.Of<ArticleReference>(() => articleReferenceAlias)
                    // There is no way of matching references to documents from a domain
                    // point of view since the references are value objects and
                    // therefore don't have an ID.
                    .Where(n => ...)
                    .Select(q => articleReferenceAlias.Number))
                .WithAlias(() => model.ArticleNumbers)
            .TransformUsing(Transformers.AliasToBean<IntermediateModel>());
            .Future<IntermediateModel>()
            .ToList()
            .Select(n =>
                new DocumentListItemModel()
                {
                    Id = n.Id,
                    ArticleNumbers = string.Join(", ", n.ArticleNumbers.OrderBy(p => p)),
                    ReceiveDate = n.ReceiveDate.ToString("d", CultureInfo.CurrentCulture)
                })
            .ToList();
    }

    private class IntermediateModel
    {
        public int Id { get; set; }
        public IEnumerable<string> ArticleNumbers { get; set; }
        public DateTime ReceiveDate { get; set; }
    }
}

As you can see, I can’t express the .Where statement because there is no way of matching references to documents from a domain point of view. The references are value objects and therefore don’t have an ID.

The question is: how do I fix the query to properly select the list of article numbers so I can use it in my string.Join statement to make the comma separated string?

  • 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-25T11:24:38+00:00Added an answer on May 25, 2026 at 11:24 am

    I managed to solve the problem. This is what I ended up with:

    public IList<DocumentListItemModel> ExecuteQuery()
    {
        ArticleReference articleReferenceAlias = null;
    
        return Session
            .QueryOver<Document>()
            .JoinAlias(n => n.ArticleReferences, () => articleReferenceAlias,
                JoinType.LeftOuterJoin)
            .SelectList(list => list
                .Select(n => n.Id)
                .Select(n => articleReferenceAlias.Number))
            .List<object[]>()
            .Select(x => new
            {
                Id = (int)x[0],
                ArticleNumber = (string)x[1]
            })
            .GroupBy(n => n.Id).Select(n =>
            {
                return new DocumentListItemModel
                {
                    Id = n.First().Id,
                    ArticleNumbers = string.Join(", ", n.Select(p => p.ArticleNumber))
                };
            }).ToList();
        }
    }
    

    I couldn’t use the alias-to-bean transformer anymore because it cannot handle collection properties. That’s why the solution has the GroupBy, it consolidates the rows, aggregating the article numbers into a string.

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

Sidebar

Related Questions

I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a simple data model in JPA (hibernate) consisting of many to one
Hay all, i have a simple model like this def Article(models.Model): upvotes = models.ManyToManyField(User,
I have this simple django model consisting of an sensor and values for the
I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50,
I have a simple Poco-Model using abstract classes, and it seems not to work
i have very simple problem. I need to create model, that represent element of
I'm relatively new to the Component Object Model specification - I have a simple
I got a simple problem in SQLAlchemy. I have one model in a table,
I have simple user model: var user = Backbone.Model.extend({ initialize: function(){ this.bind(change:auth, function (){

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.