views:

425

answers:

1

I have an IDictionary on an object which I'm loading with the following mapping:

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>

This works fine, the Valuation object doesn't have a ValuationDate on it but Nhibernate is loading the ValuationDate into the key of the dictionary as desired. I want to query the InternalFund retrieving just one Valuation specifying the ValuationDate. I've managed to do this using the index() function in HQL:

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

Again this is fantastic and exactly what I want producing the following where clause:

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

But I'd really like to do this in a DetachedCriteria to preserve the sanity of my project. When I try

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

Or

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

It says:

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

Is there a way to run index() with a DetachedCriteria?

Thanks

Stu

A: 

I believe that it is not possible (yet?)

See this feature-request / improvement request on NHibernate JIRA.

Frederik Gheysels