Additional relation duplicates results in TypedList

Posts   
 
    
Posts: 5
Joined: 09-Sep-2008
# Posted on: 10-Sep-2008 16:08:56   

Hi there

(LLBLGen 2.6, adapter)

I have a simple shop solution that consists of the following entities: - ProductEntity - OrderEntity - OrderedProductEntity

...accordingly, there is an m:n relation between products and orders through the OrderedProduct entity.

I need to aggregate order data from a product's perspective in order to do some simple analysis. For this, I created a simple TypedList, that provides the following information:

  • ProductId (GROUPBY)
  • OrderStatus (GROUPBY)
  • Total ordered products: SUM(OrderedProduct.Quantity)

Now, I want to filter my products based on fourth table that provides localized product names (several per product), in order to do something like this before aggregating:

SELECT [...] from Products INNER JOIN OrderedProducts [...]
  WHERE ProductId IN (
    SELECT ProductId from ProductLocalization WHERE ProductName = "Lenovo Thinkpad T61"
  )

However, in order to define a predicate to filter in the ProductLocalization table, I need to add a relation to my RelationPredicateBucket:

IRelationPredicateBucket filter = myTypeList.GetRelationInfo(); filter.Relations.Add(ShopProductEntity.Relations.ProductLocalizationEntityUsingProductId);

Now this is a problem: As soon as I add this relationship (without even specifying a filter), LLBLGen retrieves duplicates for my TypedList which results in wrong aggregates. I have currently three translations defined, so this is my result for a product "17" before and after having added the relation:

BEFORE: row.ProductId = 17, Quantities: 102 AFTER: row.ProductId = 17, Quantities: 306

How can I prevent this?

Thanks for your advice Philipp

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 10-Sep-2008 18:10:00   

WHERE ProductId IN ( SELECT ProductId from ProductLocalization WHERE ProductName = "Lenovo Thinkpad T61"

To specify the above predicate you don't need to Join (no need for that relation). Just use FieldCompareSetPredicate().