NHibernate load object with subcategory part

Is there a way to load NHibernate object with child collection clause? I have a script in which I register changes in "Activities", that is, one operation can contain changes for several objects. When I want to load the log for a specific object, I load all operations with any changes made to that object. Loading these operations results in all changes being loaded - I want the corresponding changes to be loaded.

Classes:

public class Operation{
   public virtual DateTime TimeStamp { get; set; }
   public virtual IList<Change> Changes { get; private set; }
}

public class Change{
    public virtual string ChangeText { get; set; }
    public virtual int EntityId { get; set; }
} 

      

Getting operations for a given object

 Session.QueryOver<Operation>().Where(o => o.Changes.Any(c => c.EntityId == entityId));

      

+2


source to share


1 answer


I am. As pointed out in this answer by Oskar Berggren: fooobar.com/questions/2154923 / ... you can apply filter 18.1. NHibernate filters

Summary:

Customize the display

<set ...>
    <filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
</set>

      



And then call it like this:

ISession session = ...;
session.EnableFilter("myFilter").SetParameter("myFilterParam", "some-value");
IList results = Session.QueryOver<Operation>()
  .Where(...
  .List();

      

II. Another option is to filter Changes

on request Operation

: 16.4. Associations

IQueryOver<Operation,Change> query =
 session.QueryOver<Operation>()
   .JoinQueryOver<Change>(o => o.Changes) // added explicit <Change>
     .Where(c => c.EntityId == entityId);

      

0


source







All Articles