【问题标题】:NHibernate self referencing queryNHibernate 自引用查询
【发布时间】:2010-07-14 08:19:00
【问题描述】:

你如何在 NHibernate 中编写这个?

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

编辑:不使用 sql 的情况

其中有两个表 TypeA 和 TypeB,其中 typeB 创建 typeA 对象并保留对最后创建的对象的引用。

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

【问题讨论】:

  • 您希望从这个查询中得到什么 SQL?

标签: c# nhibernate criteria


【解决方案1】:

所以如果你有类似的东西

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

你可以这样写:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    相关资源
    最近更新 更多