(独立)HQL 的“索引”的等效标准;功能
我在一个对象上有一个 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 的一项 Valuation。我已经设法使用 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() ?
谢谢斯图
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这是不可能的(还?)
请参阅此功能请求/改进NHibernate JIRA 上的请求。
I believe that it is not possible (yet?)
See this feature-request / improvement request on NHibernate JIRA.