In my Returns Manager, I have a class OrderReturn which has an OrderId field used to link back to the original Able order object. The OrderReturn object works perfectly, until I try to reference child classes on the linked OrderReturn.Order object.
I can access OrderReturn.Order properties just fine, like OrderReturn.Order.OrderNumber
I can access OrderReturn.Order.User properties just fine, like OrderReturn.Order.User.LoweredEmail
I can even access OrderReturn.Order.Payments collection.
But any time I try to access OrderReturn.Order.Shipments, nHibernate throws the lazy load error. Any suggestions why? Have I missed some sort of obscure nHibernate mapping reference somewhere?
All I'm doing is using an internal method in the class to send emails. But I keep getting the Lazy Load when I try to load up various collections as parameters before telling the messaging engine to send the email.
Error generating email messages for template 'Return Authorized' having subject 'RMA # $orderreturn.ReturnNumber'.
Exception: Initializing[CommerceBuilder.Orders.Order#81360]-failed to lazily initialize a collection of role: CommerceBuilder.Orders.Order.Shipments, no session or session was closed Stack Trace: at NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationException(String message) at NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationExceptionIfNotConnected() at NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writing) at NHibernate.Collection.PersistentBag.GetEnumerator() at NVelocity.Runtime.Directive.Foreach.GetIterator(IInternalContextAdapter context, INode node) at NVelocity.Runtime.Directive.Foreach.Render(IInternalContextAdapter context, TextWriter writer, INode node) at NVelocity.Runtime.Parser.Node.ASTDirective.Render(IInternalContextAdapter context, TextWriter writer) at NVelocity.Runtime.Parser.Node.SimpleNode.Render(IInternalContextAdapter context, TextWriter writer) at NVelocity.App.VelocityEngine.Evaluate(IContext context, TextWriter writer, String logTag, TextReader reader) at CommerceBuilder.Messaging.NVelocityEngine.Process(Hashtable parameters, String template) in D:\AbleMods-Client Projects\LanShack\Projects\AbleSource\CommerceBuilder\Messaging\NVelocityEngine.cs:line 61 at CommerceBuilder.Messaging.EmailTemplate.GenerateMailMessages() in D:\AbleMods-Client Projects\LanShack\Projects\AbleSource\CommerceBuilder\Messaging\EmailTemplate.cs:line 360 at CommerceBuilder.Messaging.EmailTemplate.Send(Boolean async) in D:\AbleMods-Client Projects\LanShack\Projects\AbleSource\CommerceBuilder\Messaging\EmailTemplate.cs:line 575
Code: Select all
try
{
string bccEmail = AbleContext.Current.Store.Settings.GetValueByKey("am_RMBCCEMail");
// Now with the order and email template validated, we can proceed with template construction
template.ToAddress = this.Order.BillToEmail;
// If site admin requests BCC, set the address here
if (!string.IsNullOrEmpty(bccEmail))
{
template.BCCList = bccEmail;
}
template.Parameters.Add("order", this.Order);
template.Parameters.Add("shipments", this.Order.Shipments);
template.Parameters.Add("store", AbleContext.Current.Store);
template.Parameters.Add("orderreturn", this);
template.Parameters.Add("returnitems", this.ReturnItems);
template.Parameters.Add("customer", this.Order.User);
template.Parameters.Add("payments", this.Order.Payments);
// only add user object if user exists for the return
if (this.User != null)
{
template.Parameters.Add("returnuser", this.User);
}
template.Send();
}
catch (Exception ex)
{
Common.LogEvent("Return Number " + this.ReturnNumber + " with email template trigger '" + template.Name + "' crashed with error: " + ex.Message);
}