Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

Unlinking MetaField from MetaClass programmatically

$
0
0

I am not able to delete MetaField programmatically, because said MetaField are linked to MetaClass/MetaClasses and therefore cannot be deleted. Below code works after removing the MetaField link to MetaClass/MetaClasses manually within the Commerce Manager, but I want to automate that process.

I have read threads regarding the topic on this Forum. They all seem to be linking to another thread explaining this. That thread seems to be no longer available (https://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=142928). 

MetaDataContext metaDataContext = CatalogContext.MetaDataContext;
MetaClass metaClass = Mediachase.MetaDataPlus.Configurator.MetaClass.Load(metaDataContext, "metaclassname");
IEnumerable<MetaField> allMetaFields = metaClass.GetAllMetaFields();
foreach (MetaField metaField in allMetaFields)
{
  if (metaField.Name.Equals("metafieldname"))
    {
       MetaField.Delete(metaDataContext, metaField.Id);
    }
}

How would I go about checking for MetaField link/links to MetaClass/MetaClassses programmatically, and then delete the link, so that above code would work?


Viewing all articles
Browse latest Browse all 8020

Trending Articles