Get MetaClassName by MetaClassId

Vote:
 

Hi

Is that possible to get MetaClassName having entry.MetaClassId? MetaClass is inherited from VariationContent.

Thanks

#187979
Feb 07, 2018 19:43
Vote:
 

Just call MetaClass.Load with the ID and check Name on the loaded instance. Would you care to explain why you need this? When working with Content, which is recommended, it seems a bit strange to go into MetaClass details.

#187982
Feb 07, 2018 21:27
Vote:
 

I would even prefer to work with DTOs but there is always lack of documentation describing what is what. Content is smth that I would like to avoid.

I need to create a report which consists of a big amount of products and variations and variations of variations. The last ones are custom types.  Performance is important. I need to distinguish between standard and custom types. FindItems returns Entry structure which almost fits the report content.  

It seems weird to me that it contains MetaClassId without MetaClassName. MetaClassId seems like the only way to get the type.

#187983
Feb 07, 2018 22:23
Vote:
 

Loading the Entry type generally has much worse performance than Content, and it was actually obsoleted in the latest release.

And if you load multiple Content in batch (using IContentLoader.GetItems) it will use a DTO to load multiple entries at once and do the same for the MetaObjects containing the Content type/Meta class specific data. And it will do a lot of work processing all this data for you and loading it through the content cache which is far more efficient memory-wise than the DTO:s. So I strongly recommend working with IContentLoader (and IRelationRepository for relations).

#188006
Feb 08, 2018 9:43
Vote:
 

Thank you Magnus. It was not obvious at all.

But then how to find the contentLinks list for IContentLoader.GetItems? 

I have a structure Catalog - Category - SubCategory - Products or Variations (from old solution) - SKU

#188007
Feb 08, 2018 10:30
Vote:
 

I suggest you recurse your category Hierarchy using IContentLoader.GetChildren and find products. Then for each product, use the GetVariants extension method (which uses IRelationRepository) to get a list of ContentReferences that you can then pass to IContentLoader.GetItems. So semi-pseudocode:

foreach (var catalog in IContentLoader.GetChildren<CatalogContent>(ReferenceConverter.GetRootLink))

{

// This part needs to be recursive to handle the category tree

foreach (var category in IContentLoader.GetChildren<NodeContent>(catalog.ContentLink))

{

foreach (var product in IContentLoader.GetChildren<ProductContent>(category.ContentLink))

{

variants = IContentLoader.GetItems<VariationContent>(product.GetVariants());

...

}

}

}

Edit: Don't create giant collections of all products and variants to process them in a later step, write the code to "stream" through the tree and write your report data as you go along. Especially if the catalog is big. Or you risk running out of memory because you're holding reference to practically every content in your database.

#188008
Edited, Feb 08, 2018 10:42
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.