I'll start off by admitting my codebase is a little out of date (the latest Get was probably 12th May 2009), so the answer to this might be "Get the latest, it all works" in which case I'll be busy...
However, I've got a version of N2 up and running on ASP.NET MVC using the /Examples/MVC project as my starting point: http://www.holytrinitybeckenham.org.uk/
I'd like to automate a few more areas of this for the people that administer it, so wanted to make the link to the letter automatically pick up the latest letter.
I added the following code to my HomePage model:
private readonly NewsPage m_LatestNews = null;
public HomePage()
{
var news = N2.Find.Items.Where.Type.Eq(typeof(NewsPage))
.OrderBy.Published.Desc.MaxResults(1).Select<NewsPage>();
if (null != news)
{
m_LatestNews = news[0];
}
}
And had the following in my (strongly typed) view:
<% if (null != Model.LatestNews) {%>
<p><a href="<%=Model.LatestNews.Url %>">Letter from our vicar Nick Reed and his wife Cathryn</a></p>
<% } %>
This all appeared to work fine, until I clicked on the link in the browser, and received the following exception:
failed to lazily initialize a collection, no session or session was closed
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: NHibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
Source Error:
Line 30: where T : ContentItem Line 31: { Line 32: foreach (T item in items) Line 33: if (Match(item)) Line 34: yield return item;
|
Source File: c:\Users\Ben\Documents\Visual Studio 2008\Projects\n2_Source\src\N2\Collections\ItemFilter.cs Line: 32
Any recommendations as to a suitable workaround would be gratefully received.
Thanks