I have a database schema that stores one “page” with many “revisions”. Like a simple wiki.
90% of the time when I load the page, I'm just interested in the latest revision. However, sometimes I need all the changes.
With NHibernate, I can map the page to versions and tell it lazy loading. However, when I access the latest version, it will load all other changes - a big waste of I / O.
My page class currently looks like:
public class Page
{
public Page()
{
Revisions = new HashedSet<Revision>();
}
public virtual ISet<Revision> Revisions { get; private set; }
public virtual Revision LatestRevision
{
get { return Revisions.OrderByDescending(x => x.Revised).FirstOrDefault(); }
}
public virtual Revision Revise()
{
var revision = new Revision();
revision.Entry = this;
revision.Revised = DateTime.UtcNow;
Revisions.Add(revision);
return revision;
}
}
How would I simulate this so that LastRevision loads automatically when the page loads, but other versions were lazy loaded if, for example, I tried to repeat them?
, LINQ to NHibernate, ICriteria ( SQL, ) .