Testing for the existance of one or more related entities

Posts   
 
    
JayBee
User
Posts: 282
Joined: 28-Dec-2006
# Posted on: 05-Mar-2008 14:05:07   

Hi,

I'm using SelfServicing.

I have a gridview filled with data from one entity AAA that has a 0:m relation with another entity BBB. When the user selects an entity I and that entity has 0 related entities, the user is allowed to delete that entity.

Currently I am testing the existence of related entities using AAAEntity.BBB.Count. However, the usage of AAAEntity.BBB results in the loading of all BBB entities. This could cause unnecesary performance problems.

Is there another way to test for the existance of at least 1 BBB entity? Or should I add a boolean to AAA specifying that related BBB entities exist?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Mar-2008 15:06:49   

If you want to check the existance of related records in the database, you can issue something like:

SELECT Count(*) FROM BBB
WHERE AAAId = xxx

Which can be executed using:

int numberOfRecords = BBBCollection.GetDBCount(new PredicateExpression(BBBFields.AAAId == myAAA.Id), null);
JayBee
User
Posts: 282
Joined: 28-Dec-2006
# Posted on: 05-Mar-2008 15:09:13   

Thanks