I am having the following entity + mapping:
public class Entity
{
public virtual int Id { get; set; }
public virtual ICollection Tags { get; set; }
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Test"
namespace="Test">
<class Entity">
<id name="Id"/>
<set name="Tags" table="WebcastTag">
<key column="WebcastId"/>
<element column="Tag"/>
</set>
</class>
</hibernate-mapping>
I would like to query for the existing of a tag via either the Criteria api
or the query over api but cannot seem to get it working. HQL and Linq do
work but cannot be used here as this is part of a very huge search query
that I rather keep in as a criteria api. I can select the tags via the
criteria api but I cannot query on it. I found some web pages mentioning
Restrictions.Sql but it is not available in NHibernate v3.1.0.4000 which is
the version that I am using.
// Linq query on tag
(from x in Session.Query<Entity>() where x.Tags.Contains("test") select
x).ToArray();
// Linq select all tags
(from x in Session.Query<Entity>() from t in x.Tags select t).ToArray();
// Hql query on tag
Session
.CreateQuery("from Webcast w join w.Tags t where t = :tag")
.SetString("tag", "test")
.List();
// Hql select all tags
Session
.CreateQuery("select distinct t from Webcast w join w.Tags t")
.List();
// Criteria api select all tags
Session
.CreateCriteria<Entity>("w")
.CreateCriteria("Tags", "t")
.SetProjection(
Projections.SqlProjection("Tag", new[] { "Tag" },
new[] { NHibernate.NHibernateUtil.String }))
.List();
I
--
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.