Check if a relation exists

Posts   
 
    
Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 11-Oct-2010 09:03:38   

I have to tables

Table 1 Table2 ID ID Name Table1Id Name

I have a relation between the two

bucket.Relations.Add(Table1Entity.Relations.Table1UsingId, JoinHint.Left);

Now i am doing a fetch into a data table. How do i check that there is a row in Table2 with a Table1Id. This is not always true sometime there may be no row.

I tried bucket.PredicateExpression.Add(Table2Fields.Table1Id != null);

Which fails please any suggestions. Please no linq i tried it and you can view the problem in the linq to llblgen thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=18822

Thanks in advance

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 11-Oct-2010 09:34:28   

It's not clear from your question or the code you have posted what you are trying to do.

My best guess is that you want to fetch records from table1 where there is no reference for them in Table2.

If so then you should use something like: Code: SELECT * FROM Table1 WHERE Id NOT IN (SELECT table1ID From Table2 )

This can be implemented using FieldCompareSetPredicate passing "true" for the negate parameter.

Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 11-Oct-2010 09:43:36   

Thanks that is just what i am looking for.