2

我在使用以下映射加载的对象上有一个 IDictionary:

public class InternalFund : IInternalFund
{
    public virtual IDictionary<DateTime, IValuation> Valuations { get; set; }
}

<class name="InternalFund">
      <map name="Valuations">
        <key>
          <column name="FundID" />
        </key>
        <index type="DateTime" column="ValuationDate" />
        <one-to-many class="Echo.EchoDomain.Portfolio.Valuation" />
      </map>
</class>

这很好用, Valuation 对象上没有 ValuationDate 但 Nhibernate 正在根据需要将 ValuationDate 加载到字典的键中。我想查询 InternalFund,只检索一个指定 ValuationDate 的估值。我已经设法使用 HQL 中的 index() 函数来做到这一点:

"from InternalFund i left join fetch i.Valuations v where index(v)='2009-09-30'"

再次,这太棒了,正是我想要生成以下 where 子句:

((valuations1_.ValuationDate='2009-09-30' )) 

但我真的很想在 DetachedCriteria 中这样做,以保持我的项目的理智。当我尝试

.Add(Restrictions.Eq("index(Valuations)", valuationDate));

或者

.CreateAlias("Valuations", "v", JoinType.LeftOuterJoin)
.Add(Restrictions.Eq("index(v)", valuationDate));

它说:

QueryException: could not resolve property: index(v) of: Echo.EchoDomain.Fund.InternalFund

有没有办法使用 DetachedCriteria 运行 index()?

谢谢

斯图

4

1 回答 1

1

我相信这是不可能的(还没有?)

请参阅NHibernate JIRA 上的功能请求/改进请求。

于 2009-09-24T10:32:40.353 回答