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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:26:44+00:00 2026-06-06T05:26:44+00:00

In my domain I have something called Project which basically holds a lot of

  • 0

In my domain I have something called Project which basically holds a lot of simple configuration propeties that describe what should happen when the project gets executed. When the Project gets executed it produces a huge amount of LogEntries. In my application I need to analyse these log entries for a given Project, so I need to be able to partially successively load a portion (time frame) of log entries from the database (Oracle). How would you model this relationship as DB tables and as objects?

I could have a Project table and ProjectLog table and have a foreign key to the primary key of Project and do the “same” thing at object level have class Project and a property

IEnumerable<LogEntry> LogEntries { get; }

and have NHibernate do all the mapping. But how would I design my ProjectRepository in this case? I could have a methods

void FillLog(Project projectToFill, DateTime start, DateTime end);

How can I tell NHibernate that it should not load the LogEntries until someone calls this method and how would I make NHibernate to load a specifc timeframe within that method?

I am pretty new to ORM, maybe that design is not optimal for NHibernate or in general? Maybe I shoul design it differently?

  • 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-06T05:26:46+00:00Added an answer on June 6, 2026 at 5:26 am

    The ‘correct’ way of loading partial / filtered / criteria-based lists under NHibernate is to use queries. There is lazy="extra" but it doesn’t do what you want.

    As you’ve already noted, that breaks the DDD model of Root Aggregate -> Children. I struggled with just this problem for an absolute age, because first of all I hated having what amounted to persistence concerns polluting my domain model, and I could never get the API surface to look ‘right’. Filter methods on the owning entity class work but are far from pretty.

    In the end I settled for extending my entity base class (all my entities inherit from it, which I know is slightly unfashionable these days but it does at least let me do this sort of thing consistently) with a protected method called Query<T>() that takes a LINQ expression defining the relationship and, under the hood in the repository, calls LINQ-to-NH and returns an IQueryable<T> that you can then query into as you require. I can then facade that call beneath a regular property.

    The base class does this:

    protected virtual IQueryable<TCollection> Query<TCollection>(Expression<Func<TCollection, bool>> selector)
            where TCollection : class, IPersistent
        {
            return Repository.For<TCollection>().Where(selector);
        }
    

    (I should note here that my Repository implementation implements IQueryable<T> directly and then delegates the work down to the NH Session.Query<T>())

    And the facading works like this:

    public virtual IQueryable<Form> Forms 
    { 
        get 
        { 
             return Query<Form>(x => x.Account == this); 
        } 
    }
    

    This defines the list relationship between Account and Form as the inverse of the actual mapped relationship (Form -> Account).

    For ‘infinite’ collections – where there is a potentially unbounded number of objects in the set – this works OK, but it means you can’t map the relationship directly in NHibernate and therefore can’t use the property directly in NH queries, only indirectly.

    What we really need is a replacement for NHibernate’s generic bag, list and set implementations that knows how to use the LINQ provider to query into lists directly. One has been proposed as a patch (see https://nhibernate.jira.com/browse/NH-2319). As you can see the patch was not finished or accepted and from what I can see the proposer didn’t re-package this as an extension – Diego Mijelshon is a user here on SO so perhaps he’ll chime in… I have tested out his proposed code as a POC and it does work as advertised, but obviously it’s not tested or guaranteed or necessarily complete, it might have side-effects, and without permission to use or publish it you couldn’t use it anyway.

    Until and unless the NH team get around to writing / accepting a patch that makes this happen, we’ll have to keep resorting to workarounds. NH and DDD just have conflicting views of the world, here.

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

Sidebar

Related Questions

Following is the scenario. I have something called as Domain which can have multiple
I have a Map, that I want to persist. The domain object is something
Let's say I have a domain class called User which can follow other User
I have a domain called example.com that takes a parameter ?ref=XXXXXX . The referral
I have an MVC3 project that is using an EF4 project as its Domain.
I have a domain Aggregate, call it Order that contains a List of OrderLines.
i have a domain full-ops.com that i transferred to another host, but it takes
Problem domain We have Projects and Milestones Once created, a Milestone has a Project
I have a custom UIButton in my viewcontroller that should have either the image
I have a domain called olddomain.com . Now I want to point the DNS

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.