Using GetCatalogEntriesDto to bulk load Entry instances

Vote:
 

Hey Everyone,

Stuck on a little bit of a brain teaser. Currently, I get all product variations via their ContentReference.ID and use this to get an Entry instance in a foreach loop.

  if (variationsList != null && variationsList.Count() > 0)
{
foreach (var item in variationsList)
{
var thisEntry = CatalogRef.GetCatalogEntry(item.Target.ID, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Variations));



I'm trying to optimise code (cut down database calls) so that we bulk load in CataLogEntries as Entry instances (Probably store these in a dictionary or List). I'm hoping to use the the GetCatalogEntriesDto method to load Entry instances before entering the foreach loop and then using LINQ get a particular Entry instance based on ContentReference.ID something like:

var thisEntry = entryDto.Variation.Single(x => x.CatalogEntryId == item.Target.ID);



Can anyone advise here please?

Best,

John

#182407
Sep 18, 2017 14:52
Vote:
 

Hi John,

Is it this you're looking for?

ILinksRepository.GetRelationsBySource(new ContentReference(ParentId)).OfType<ProductVariation>().OrderBy(r => r.SortOrder);

PS, this thread should be posted into the commerce forum

Regards

#182411
Edited, Sep 18, 2017 15:05
Vote:
 

Thanks Gosso, 

I will try this out - I'll let you know if it works!

Best,

John

#182413
Sep 18, 2017 15:18
Vote:
 

Unless you have a specific reason to load the DTO or Entry objects I would really recommend working with the catalog data as IContent using IContentLoader. IContentLoader.GetItems can be used to batch load content.

BTW, don't use the ID part of the content link as the ID of a low-level catalog entity like an entry or node. To convert between ContentReferences and ID:s for catalog entities, use ReferenceConverter.GetObjectId to make sure the conversion is done correctly.

#182414
Sep 18, 2017 15:20
Vote:
 

I moved this thread to Commerce forum

What are you trying to do with the Entry(s)? As Rahl said we recommend to use the content APIs (IContentLoader etc.). Loading an Entry also means loading prices and inventories (even when you don't need them), and an Entry object has a quite poor reuseable so caching is pretty limited. 

#182417
Sep 18, 2017 15:56
Vote:
 

Hey Guys, 

I'm trying to bulk load entries via the GetCatalogEntriesDto so I can access the ItemAttributes of the Entry, does that make sense?

Best,

John

#182447
Sep 19, 2017 13:04
Vote:
 

When you load the IContent you can access the properties via Property. Or even better, if you use strongly typed content types, inherited from ProductContent, VariantionContent, etc., you can access the properties in a strong typed maner, so instead of ItemAttributes["AHiddeTypo"], you can make it productContent.AHiddenTypo.

Spot the difference?

#182448
Sep 19, 2017 13:08
Vote:
 

Hey Guys,

The IContentLoader solution worked for me!

Thannks for all your help!

Best,

John

#183311
Oct 11, 2017 10:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.