prefetch with filtering

Posts   
 
    
ZHaun
User
Posts: 1
Joined: 04-Aug-2006
# Posted on: 04-Aug-2006 12:33:53   

Hi, i'm using selfservicing and have a general implementation question.

i have essentialy these tables.


product
  productid
  productprice

producttext
  productid
  languageid
  description
  header

language
  languageid
  languagename

when a product is entered a producttext is automaticaly created in a (required) main language.

the products and text are entered by our customers, and every product can have multiple text entries in different languages. But when viewing the data in a certain langauge we have to ensure that they SEE text so if the requested language is not entered in the producttext table then i want to ensure that they get the (required) main language.

After we have to show a list of 200+ products, our current code is too slow. it simply runs though products and creates a producttext entity, checks on its state is loaded or not, and if not then grabs the other. this means that there could be 400 querys reading producttext while looping though 200 items.

I'd like to prefetch the producttext when getting the products, but not all languages, just the requested language or the required language if the requested is not present in the database.

the following query gets the productid and the language to use, that could be used in a subquery to get the result, but i'm having a real problem implementing this though llbgen-selfservicing code.


SELECT ProductId, ISNULL(ProductText.LanguageId,2) AS LanguageId
FROM 
    Product LEFT OUTER JOIN
    ProductText ON 
    ((Product.ProductId = ProductText.ProductId) AND
    (ProductText.LanguageId = 4))

2 is the required text that is guaranteed to be in the database, and 4 is the requested language.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 04-Aug-2006 15:22:53   

Hi,

here's something you're code might look like (vb.net) , to prefetch the product with texts for the required and requested languages:

dim requiredLanguageID as integer dim requestedLanguageID as integer '...get the values

Dim products As New ProductCollection() Dim prefetchPath As IPrefetchPath = New PrefetchPath(CType(EntityType.ProductEntity, Integer)) prefetchPath.Add(ProductEntity.PrefetchPathProductText) Dim filter As IPredicateExpression = New PredicateExpression() filter.Add((ProductTextFields.LanguageId = requiredLanguageID) OR (ProductTextFields.LanguageId = requestedLanguageID )) orders.GetMulti(filter, prefetchPath)

Hope that helps