Criteria for finding items containing a specific item in a bag

6 views
Skip to first unread message

Tobi

unread,
Sep 1, 2008, 8:18:13 AM9/1/08
to nhu...@googlegroups.com
Having a class "Product" which has a property "EnhancedArticleNumbers"
which is a list of strings, mapped as a bag, how can I query a Product
that has a specific article number?

It's easy to do in HQL, but I'm interested if and how this can be done
using the Criteria API.

The relevant part of the mapping is:

<class name="Foo.Bar.Product, Foo.Bar">
<bag name="EnhancedArticleNumbers" access="nosetter.camelcase-underscore">
<key column="Product"/>
<element column="Number" type="string" length="20" unique="true"/>
</bag>
</class>

What I would like to do is something like this:

ICriteria criteria =
session.CreateCriteria(typeof(Product))
.Add(Expression.Contains("EnhancedArticleNumbers", anArticleNumber));

But there is no "Expression.Contains()", so is there another way to do
this? (without making the article numbers a separate class)

Tobias

Ken Egozi

unread,
Sep 1, 2008, 11:02:11 AM9/1/08
to nhu...@googlegroups.com

Tobi

unread,
Sep 1, 2008, 11:36:47 AM9/1/08
to nhu...@googlegroups.com
Ken Egozi wrote:

> SubQueries.In

But SubQueries.In() wants a DetachedCriteria and I only have a single
class "Product" with a bag of strings. So how should the DetachedCriteria
then look like if there is no class "EnhancedArticleNumber"?

SessionManager.CurrentSession.CreateCriteria(typeof(Product))
.Add(Subqueries.In(anArticleNumber, new DetachedCriteria(typeof(???))


Tobias

Ken Egozi

unread,
Sep 1, 2008, 11:56:19 AM9/1/08
to nhu...@googlegroups.com
sorry, missed the <element> and string parts
Reply all
Reply to author
Forward
0 new messages