Here's my (simplified) model: Ticket -> Client Callback
I have my own Ticket displayed so that when it is loaded, callbacks also exist.
base.HasMany<TechSupportCallback>(x => x.Callbacks) .KeyColumn(Fields.TRACKED_ITEM_ID) .Not.LazyLoad() .Inverse() .Cache.ReadWrite();
This is not lazy loading, because otherwise I get "no session to load objects" when the web service tries to serialize (and load) the proxy. (Using repositories to retrieve data.)
It is also bidirectional ... (in reverse request)
base.References(x => x.Ticket) .Column(Fields.TRACKED_ITEM_ID) .Not.Nullable();
Now we need to show the agent a list of our callbacks - ONLY their callbacks. - When I request the use of criteria for callbacks, I cannot prohibit the download of the ticket (and then its entire schedule, including other collections). Earlier, I tried to set FetchMode.Lazy, then iterate over every Callback received and set Ticket to null, but this seems to be ignored.
// open session & transaction in using (..) var query = session.CreateCriteria<TechSupportCallback>() .SetCacheable(true) .SetCacheRegion("CallbacksByUserAndGroups") .SetFetchMode("Ticket", FetchMode.Lazy) // <-- but this doesn't work! .SetMaxResults(AegisDataContext.Current.GetMaxRecordCount()) ; rValue = query.List<TechSupportCallback>(); rvalue.ForEach(x => x.Ticket = null;); // <-- since this is already retrieved, doing this merely prevents it from going back across the wire tx.Commit(); // usings end (..)
Should I do this using projection? The problem with this. I could not find an example of the forecasts used to populate the object or their list - only for use as a subquery in a child object or something similar to limit the list of parent objects.
I could use some recommendations about this.
[EDIT]
I tried using projection as intended, but:
I get the following: (this was due to an error, and so I have since stopped using the cache and it works. Http://nhibernate.jira.com/browse/NH-1090 )
System.InvalidCastException occurred Message=Unable to cast object of type 'AEGISweb.Data.Entities.TechSupportCallback' to type 'System.Object[]'. Source=NHibernate StackTrace: at NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session) InnerException:
in
rValue = query.List<TechSupportCallback>();
with projection list defined as
displayed as
public TechSupportCallbackMap() { base.Cache.ReadWrite(); base.Not.LazyLoad(); base.Table("TS_CALLBACKS"); base.Id(x => x.ID, Fields.ID) .GeneratedBy.Sequence("SEQ_TS_CALLBACKS"); base.References(x => x.Ticket) .Column(Fields.TRACKED_ITEM_ID) .Not.Nullable(); base.Map(x => x.TrackedItemID, Fields.TRACKED_ITEM_ID) .Not.Insert() .Not.Update() .Generated.Always() ;