CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

PreInsertEvent

186 Views
Copy Code Show/Hide Line Numbers
public bool OnPreInsert(PreInsertEvent @event)
{
    var entity = @event.Entity as ParentVersion;
    if (entity == null)
    {
        return false;
    }
 
    var currentMaxVersion = @event.Session.CreateCriteria<ParentVersion>("pv")
        .Add(Restrictions.Eq("pv.Parent.Id", entity.Parent.Id))
        .SetProjection(Projections.Max("pv.Version"))
        .UniqueResult<int>();
 
    Set(@event.Persister, @event.State, "ParentVersion", currentMaxVersion + 1);
 
    return false;
}
by Mikael Henriksson
  November 19, 2009 @ 1:09pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate