views:

25

answers:

1

How do you write this in NHibernate?

criteria
    .CreateAlias( "CreatorObject.LastCreated", "me" )
    .Add( Restrictions.Eq( this, "me" ) );

Edit: something like this without using sql

Where there are two tables TypeA and TypeB where typeB creates typeA objects and keeps a reference to the last object created.

criteria
.Add( Restrictions.IdEq( Projections.SqlProjection( "(Select LastCreated From Creators Where Creators.Id = CreatorId) as MasterId", new[] { "MasterId" }, new[] { NHibernateUtil.Int32 } ) ) );
A: 

So if you have something like

public class SomeClass {
  public SomeClass LastCreated { get; set;}
  public SomeClass CreatorObject {get; set;}
}

you could write something like:

criteria.Add(Restrictions.Eq("CreatorObject.LastCreated", this));
David