我在构建正确的标准以执行特定查询时遇到了一些麻烦 - 经过与Google教授的一个下午咨询,我希望有人能指出我正确的方向。如何在有<any>关联时编写标准查询
我有两个实体:OutputTsDef
和NamedAttribute
我试图做的是要找到具有特定NamedAttribute
值的所有OutputTsDef
。
我可以写一个分离的标准来寻找有 所有NamedAttributes
给定的名称和值:
var attributesCriteria
= DetachedCriteria.For<INamedAttribute>()
.Add(Expression.Eq("Name", "some name"))
.Add(Expression.Eq("Value", "some value"));
如何注入这在一个查询OutputTsDef限制的结果?
var criteria
= nHibernateSession.CreateCriteria(typeof(IOutputTsDefEntity));
// What do I write here?
var results = criteria.List();
NamedAttribute
看起来是这样的 - 注意使用[Any]
因为我们可以有多种实体的 NamedAttributes
。
[AttributeIdentifier("DbKey", Name = "Id.Column", Value = "NamedAttributeID")]
[Class(Table = "NamedAttributes")]
public class NamedAttribute : BusinessEntity, INamedAttribute
{
[Any(0, Name = "Entity", MetaType = "System.String", IdType = "System.Int32")]
[MetaValue(1, Class = "Sample.OutputTsDef, Sample.Entities", Value = "OTD")]
[MetaValue(2, Class = "Sample.OutputTimeSeriesAttributesEntity, Sample.Entities", Value = "OTA")]
[Column(3, Name = "OwnerType")]
[Column(4, Name = "OwnerKey")]
public virtual IBusinessEntity Entity { get; set; }
[Property(Column = "Name")]
public virtual string Name { get; set; }
[Property(Column = "Value")]
public virtual string Value { get; set; }
... omitted ...
}
在常规的SQL,我只是包括一个额外的 “where” 子句是这样的:
where OutputTsDefId
in (select distinct OwnerKey
from NamedAttributes
where Name = ?
and Value = ?
and OwnerType = 'OTD')
我缺少什么?
(问题也张贴到NHUsers邮件列表 - 我会任何有用的信息从那里复制,在这里。)
不是,没有。感谢指针,但。 – Bevan 2010-05-03 20:34:42