Hi everyone.

I'm having some trouble constructing the correct Criteria to do a
particular query - after an afternoon of consultation with Professor
Google, I'm hoping that someone can point me in the right direction.

I have two entities of interest: OutputTsDef and NamedAttribute

What I'm trying to do is to find all OutputTsDef that have a
particular NamedAttribute value.

I can write a detached Criteria to find all NamedAttributes that have
a given name and value:

            var attributesCriteria
                = DetachedCriteria.For<INamedAttribute>()
                    .Add(Expression.Eq("Name", "some name"))
                    .Add(Expression.Eq("Value", "some value"));

How do I inject this in to a query for OutputTsDef to restrict the results?

            var criteria
                = nHibernateSession.CreateCriteria(typeof(IOutputTsDefEntity));
            // What do I write here?
            var results = criteria.List();

NamedAttribute looks like this - note the use of [Any] as we can have
NamedAttributes on many kinds of entity.

    [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 ...
    }

In regular SQL, I'd just include an extra "where" clause like this:

where OutputTsDefId
      in ( select distinct OwnerKey
           from NamedAttributes
           where Name = ?
             and Value = ?
             and OwnerType = 'OTD' )

What am I missing?

Thanks for your time,
Bevan.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to