开发者

Selecting by specific elements in a list in HQL

I'm implementing a "QueryEngine" design pattern for dynamic queries

on with loose connection to a Query Language (Like LINQ).

I am having a hard time writing the HQL for a specific elemt from a list.

i.e:

public class Cat()
{
    public int ID { get; set; }
    public string Name { get; set; }
    public Cat Child { get; set; }
}

Now I'm trying to select a cat by his child, so the HQL should be something like this:

SELECT cat FROM CAT as cat  
WHERE cat.Child = {"Any value or subsearch"}

But if I alter the Cat class to have a one-to-many reference:

public class Cat()
{
    public int ID { get; set; }
    public string Name { get; set; }
    public IList<Cat> Children { get; set; }
}

The HQL will now look like this (I'm trying to select by a specific child in the list)

SELECT cat FROM CAT as cat  
WHERE {"Any value or subsearch"} IN elements(Children}

My question is, Can I make the second query to be similiar in the order to the 开发者_StackOverflow社区first one

Something like this:

SELECT cat FROM CAT as cat  
WHERE Children CONTAIN {"Any value or subsearch"}

Thanks [=


You are probably looking for something like this:

select cat from Cat cat
    join cat.Children child
    where child.Something is true


Neither HQL nor Linq are great for dynamically constructed queries.

I suggest you use Criteria instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜