exists keyword

Posts   
 
    
nefise
User
Posts: 22
Joined: 01-Dec-2006
# Posted on: 12-Jul-2007 09:16:47   

LLBLGEN PRO 2.0 Adapter .Net 2005 Oracle / SqlServer

How can i simulate "exists" keyword in llblgen by the generated code?

For example :

select * from table_a where exists (select distinct(table_a_key) from table_b)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jul-2007 10:01:31   

Please check the FieldCompareSetPredicate (ref: LLBLGen Pro manual: "Using the generated code -> SelfServicing/Adapter -> Filtering and sorting -> The predicate system")

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 12-Jul-2007 13:35:26   

the final output would look like this

select a.* from table_a where a.PK in (select b.key_for_a from table_b b)
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jul-2007 15:43:09   

This will return the same results.

nefise
User
Posts: 22
Joined: 01-Dec-2006
# Posted on: 17-Jul-2007 08:31:52   

I am trying to simulate a query with "not exists" which SetOperater can i use? I tried this : filter.Add(new FieldCompareSetPredicate( AFields.No, null, BFields.No, null, SetOperator.NotEqualAny, null));

but the resultset is same as the query resultset.

3.parameter is a filter, is this filter about the exists statement What does the 5. parameter (bool negate) do?

I think the documentation is not enough for overloaded functions and parameters.

And also what is the syntax if i want to bind PKs of the query over two fields like this;

select no, sk_no from table_a where not exists(select m_no,sk_no from table_b where no = m_no and table_a.sk_no = sk_no)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Jul-2007 09:46:44   

3.parameter is a filter, is this filter about the exists statement

Yes, it is used to filter the inner query (the IN predicate).

What does the 5. parameter (bool negate) do?

If you set it to true, it would produce the NOT that you need. So the predicate would be NOT IN.

And also what is the syntax if i want to bind PKs of the query over two fields like this;

select no, sk_no from table_a where not exists(select m_no,sk_no from table_b where no = m_no and table_a.sk_no = sk_no)

The above query can be re-written to use a JOIN, as follows:

SELECT no, sk_no 
FROM table_a 
INNER JOIN table_b 
ON table_a.no = table_b.m_no
AND table_a.sk_no = table_b.sk_no

To JOIN on another table all you have to do is pass an EntityRelation object to the relationCollection used in the Fetch method, to define the JOIN between table_a and table_b. And if you are using an extra filter on the JOIN (other than the PK-FK relation). You can use the CustomFilter property of the EntityRelation used.

Please refer to the LLBLGenPro reference manual for more information.