开发者

NHibernate self referencing query

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 = Cr开发者_C百科eatorId) as MasterId", new[] { "MasterId" }, new[] { NHibernateUtil.Int32 } ) ) );


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜