Noob Question - Count of relations

Posts   
 
    
gantww
User
Posts: 4
Joined: 25-Aug-2006
# Posted on: 25-Aug-2006 00:44:26   

Hello all, I have two entities that are related by a 1:n relationship. Given an entity on the "1" side of the relationship, how can I use the UI to produce a property that will give me a count of the entities on the "n" side of the relationship. Or should I do this via code?

Mainly, I don't want to end up loading data for all those child entities when I really just need a count.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 25-Aug-2006 02:53:47   

Have you taken a look at GetDBCount? This will query the database using a filter and return the number of records that match. You can't use myEntity.RelatedEntity.Count since you would have to load the items, but you could do something like this.

DataAccessAdapter adapter = new DataAccessAdapter();
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(OrderItemFields.OrderId == order.OrderId);
int amount = (int)adapter.GetDbCount(new OrderItemEntityFactory().CreateFields(), filter, null, false);

This would return a count for all items for the specified order.

gantww
User
Posts: 4
Joined: 25-Aug-2006
# Posted on: 25-Aug-2006 03:21:16   

What I ended up doing was creating a view that exposed the information I needed. Now, I need to figure out how to make LLBL realize that the view is related to the tables in question (since I need to filter on one of them). Is there a way to link a view-based entity in as if it were table-based?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 25-Aug-2006 03:26:49   

You can map the view as an enity and define the relations in the designer.

gantww
User
Posts: 4
Joined: 25-Aug-2006
# Posted on: 25-Aug-2006 03:46:35   

Doh! That's the problem. I was looking for something more difficult. sunglasses It's fixed, plus the other three questions I came up with while waiting for a response are handled too. I figured that you couldn't do the whole relationship thing on a entity mapped to a view because of the lack of a primary key. Turns out you can. I've got some other pieces of this app to rethink now...